How to plot a parametric study on a single graph

Hi, Suppose I have a code
a= [1 32 51 24 5 23]
for i=1:length(a)
c=a(i)+d;
b=a(i)+e;
end
plot(b,c)
how do I plot all 6 cases for variation of a on the same graph ?? Basically im changing the value of a and seeing how the solution changes. I want to view it on one graph.

댓글 수: 6

KSSV
KSSV 2017년 5월 11일
YOu have not defined c..what is c? You can plot different cases on figure using hold on
Should we assume that c has been initialized as a vector? If not then your b and c would end up as scalars and plot(b,c) would not show anything.
DIP
DIP 2017년 5월 11일
Something like this
DIP
DIP 2017년 5월 11일
its basically the same calculation, im only changing one parameter and plotting it on the same graph
DIP
DIP 2017년 5월 11일
i was looking for a pseudo code or the correct syntax
I notice that you have edited your code. Are we to assume that d and e are both vectors? If they are not then your plot(b,c) is going to be plotting a scalar against a scalar.
Note: in your loop in your altered code, you are writing over all of b and all of d in each iteration of the loop. If that is your intent then you might as well only do the final iteration,
for i = length(a)
because that would have the same effect.
I did not mention this with your original code because your original code used the new value of c in the next iteration, and so could potentially have been meaningful if c was initialized to a vector.

댓글을 달려면 로그인하십시오.

 채택된 답변

KSSV
KSSV 2017년 5월 11일

1 개 추천

th = linspace(0,pi) ;
figure
hold on
for i = 1:6
x = rand*sin(rand*th) ;
plot(th,x) ;
end

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

질문:

DIP
2017년 5월 11일

댓글:

2017년 5월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by