Graph works fine for 1 value, I am trying to graph 3 values on the same plot

2 visualizaciones (últimos 30 días)
I am trying to plot extra values of N for on one graph and it is giving me an error it works for either N = 5, N=9, N=20 by themselves but not all together. As well as i want to change their line weight and their colors and the points to be all different.
N = 5 will be RED and * points
N = 9 will be BLUE and Triangle points
N = 20 will be Green and Circle points
If you run it for N = 5, I work works and plots a U shape line with 5 points. N=9 is just plotting more points as well as N = 20. I just want to plot them all together on the same graph.
w = .5; %% 2w=1
x = -.5:0.1:.5; %% X (-w,w)
N = [5, 9, 20]; %% N [5,9,20]
delta = 2*w./N;
% Matrix for W
Mat_w = zeros(N,1);
for i = 1:N
Mat_w(i) =(-w+delta.*(i-.5));
end
% U Matrix
u = ones(N,1).*(x.^2);
% F Matrix
f = ones(N,1);
% S Matrix
s = ones(N,N);
for m = 1:N
for n = 1:N
s(m,n) = delta/(2*pi)*(1-log(delta)-1/2*log(abs((m-n).^2-.25))...
-(m-n)*log(abs(m-n+.5)/abs(m-n-.5)));
end
end
u = s\f;
title('Case 2')
hold on
plot(Mat_w, u)
xlim([-w,w])
legend('N=5', 'N=9', 'N=20');
This is the error that I get when I try to plot all three at the same time.
This is the error in the Command line
Error using zeros
Size inputs must be scalar.
Error in HW9_new (line 7)
Mat_w = zeros(N,1);
  3 comentarios
Image Analyst
Image Analyst el 9 de Mayo de 2021
@RikThe archives seem to often overwrite with the latest (unless I'm just not using it correctly), so since WARRIOR has a history of deleting questions, I'm putting it here:
I am trying to plot extra values of N for on one graph and it is giving me an error it works for either N = 5, N=9, N=20 by themselves but not all together. As well as i want to change their line weight and their colors and the points to be all different.
N = 5 will be RED and * points
N = 9 will be BLUE and Triangle points
N = 20 will be Green and Circle points
If you run it for N = 5, I work works and plots a U shape line with 5 points. N=9 is just plotting more points as well as N = 20. I just want to plot them all together on the same graph.
w = .5; %% 2w=1
x = -.5:0.1:.5; %% X (-w,w)
N = [5, 9, 20]; %% N [5,9,20]
delta = 2*w./N;
% Matrix for W
Mat_w = zeros(N,1);
for i = 1:N
Mat_w(i) =(-w+delta.*(i-.5));
end
% U Matrix
u = ones(N,1).*(x.^2);
% F Matrix
f = ones(N,1);
% S Matrix
s = ones(N,N);
for m = 1:N
for n = 1:N
s(m,n) = delta/(2*pi)*(1-log(delta)-1/2*log(abs((m-n).^2-.25))...
-(m-n)*log(abs(m-n+.5)/abs(m-n-.5)));
end
end
u = s\f;
title('Case 2')
hold on
plot(Mat_w, u)
xlim([-w,w])
legend('N=5', 'N=9', 'N=20');
This is the error that I get when I try to plot all three at the same time.
This is the error in the Command line
Error using zeros
Size inputs must be scalar.
Error in HW9_new (line 7)
Mat_w = zeros(N,1);
Rik
Rik el 9 de Mayo de 2021
@Image Analyst In that case I'm curious how you're using it that you see that behavior. The Google cache links can be tricky, but normal links (at the very least with a specific date in the url) should work as expected, that is the whole point of the Wayback Machine.
They do have issues from time to time, but I don't recognize your description.

Iniciar sesión para comentar.

Respuestas (1)

Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato el 9 de Mayo de 2021
Editada: Thiago Henrique Gomes Lobato el 9 de Mayo de 2021
Each N changes the data of the plot, so you need to make it in an outer loop
w = .5; %% 2w=1
x = -.5:0.1:.5; %% X (-w,w)
allNs = [5, 9, 20];
lineWidths = [1,2,3];
symbols = {'r-*','b-^','g-o'};
for idxN = 1:length(allNs) % Each N generate its own data and plot
N = allNs(idxN);
delta = 2*w./N;
% Matrix for W
Mat_w = zeros(N,1);
for i = 1:N
Mat_w(i) =(-w+delta.*(i-.5));
end
% U Matrix
u = ones(N,1).*(x.^2);
% F Matrix
f = ones(N,1);
% S Matrix
s = ones(N,N);
for m = 1:N
for n = 1:N
s(m,n) = delta/(2*pi)*(1-log(delta)-1/2*log(abs((m-n).^2-.25))...
-(m-n)*log(abs(m-n+.5)/abs(m-n-.5)));
end
end
u = s\f;
plot(Mat_w, u,symbols{idxN},'linewidth',lineWidths(idxN))
title('Case 2')
hold on
end
xlim([-w,w])
legend('N=5', 'N=9', 'N=20');

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by