필터 지우기
필터 지우기

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