Why I am getting only points while plotting multiple graphs in single plot?
1 view (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Star Strider
on 10 Apr 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 Comments
Star Strider
on 10 Apr 2014
Edited: Star Strider
on 10 Apr 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.
More Answers (0)
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!