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

1 Ansicht (letzte 30 Tage)
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

Akzeptierte Antwort

Star Strider
Star Strider am 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 Kommentare
Tapas
Tapas am 10 Apr. 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 am 10 Apr. 2014
Bearbeitet: Star Strider am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by