Why I am getting only points while plotting multiple graphs in single plot?

1 visualización (últimos 30 días)
Here is my code for plotting multiple curves in a single plot, but I dont understand why I am getting only points instead of a line. Please suggest me.
ct=0
for mu=-90:1:90
ct=ct+1
for s= [1 2 3 4 5]
c(s)=gamma(s+1)/(gamma(s+0.5)*sqrt(pi))
d(ct)=c(s).*(cos(mu.*pi/180)).^(2.*s)
plot (mu,d(ct))
hold on
end
end

Respuesta aceptada

Star Strider
Star Strider el 10 de Abr. de 2014
It plots points because you give it points in your loop.
Try this:
ct=0;
muv = -90:1:90;
for mu = muv
ct=ct+1;
for s= [1 2 3 4 5]
c(s)=gamma(s+1)/(gamma(s+0.5)*sqrt(pi));
d(ct,s)=c(s).*(cos(mu.*pi/180)).^(2.*s);
end
end
figure(1)
plot(muv, d(:,1))
hold on
for s = 1:5
plot(muv, d(:,s))
end
hold off
grid
  2 comentarios
Tapas
Tapas el 10 de Abr. de 2014
ok thanks for the answer. i have one more query, how can i change the line style(i mean -k,--k like this) for this kind of multiple plots.
Star Strider
Star Strider el 10 de Abr. de 2014
Editada: Star Strider el 10 de Abr. de 2014
My pleasure!
There are only four LineSeries options, so they need to be continuously recycled. Only the plot in figure(1) needs to be changed, the rest of your code remains as previously posted.
This works:
linsty = {'-', '--', ':', '-.'};
figure(1)
plot(muv, d(:,1), '-.b')
hold on
for s = 2:5
cs = circshift(1:4,[0 s]);
plot(muv, d(:,s), linsty{cs(1)})
end
hold off
grid
You can do the same sort of thing for colours and markers as well, if you want to do that. They are all described in Lineseries Properties.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by