MATLAB Answers

plotting with changing variable values with switch case command

조회 수: 36(최근 30일)
Meva
Meva 3 Mar 2015
댓글: Robert Cumming 3 Mar 2015
My whole program run with a loop . It is not showing the plot when I try below:
for nt =1:30001
...
switch nt
case 0
h1=plot(x,y,x,z,'-.xr');
case 10001
h2=plot(x,y,x,z,'-.xg');
case 20001
h3=plot(x,y,x,z,'-.xk');
case 22556
h4=plot(x,y,x,z,'-.xb');
end
hold on;
legend('1','2','3','4')
How can I plot all cases?

  댓글 수: 0

로그인 to comment.

답변(1개)

Robert Cumming
Robert Cumming 3 Mar 2015
you need to specify the hold command before you start creating the plots.

  댓글 수: 2

Meva
Meva 3 Mar 2015
I have added
plot(h1,h2,h3,h4)
I used :
switch nt
case 0
h1=plot(x,y,x,z,'-.xr');
case 10001
h2=plot(x,y,x,z,'-.xg');
case 20001
h3=plot(x,y,x,z,'-.xk');
case 22556
h4=plot(x,y,x,z,'-.xb');
end
hold on;
plot(h1,h2,h3,h4)
legend('1','2','3','4')
but it does not recognise h1
Robert Cumming
Robert Cumming 3 Mar 2015
your loop starts at 1 - h1 is only activated when your loop index is 0 (doesn't look like that happens in your example)

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by