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

1 次查看(过去 30 天)
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

采纳的回答

Star Strider
Star Strider 2014-4-10
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 个评论
Tapas
Tapas 2014-4-10
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 2014-4-10
编辑:Star Strider 2014-4-10
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by