필터 지우기
필터 지우기

shouldPlot and switch case and legend and multiple figure error

조회 수: 3 (최근 30일)
Meva
Meva 2015년 3월 5일
댓글: Meva 2015년 3월 5일
Two questions about shouldPlot and switchcase:
1) I cannot locate correctly legends I mean it does not show legends for figure (1) 2) Figure (2) cannot be shown. I can usse another swicthcase but I do not want to overwrite.
shouldPlot = true;
switch nt
case 1
f = up; g = down;
c = middle;
vel1 = u1; vel2 = u2;
hold on;
case 2
f = up; g = down;
c = middle;
vel1 = u1; vel2 = u2;
otherwise
shouldPlot = false;
% disp('Quit');
end
if (shouldPlot)
figure (1);
plot(xx,f,xx,g);
legend('time 0','time 0','t clash','t clash')
hold on;
plot(xx, c);
% legend('time 0','t clash')
hold on
% axis([0 1 0 1]);
xlabel('x');
ylabel('body');
figure (2);
plot(xx,vel1,xx,vel2);
...
end

답변 (1개)

Michael Haderlein
Michael Haderlein 2015년 3월 5일
When I run the code inside your if case with random values, I do get the legend in figure 1. Of course, only f and g are described, but that's all which is plotted at the time the legend is created. Depending on the size of f and g, the legend either includes only "time 0" twice or also "t clash". c is not included in the legend as you plot c after the creation of the legend. Remember that the legend will be fully rewritten when you use the legend command. Old entries will disappear if you do not repeat them.
What do you mean with "Figure (2) cannot be shown."? Figure 2 is created and shows up just as it should.
  댓글 수: 4
Meva
Meva 2015년 3월 5일
legend certainly does not work.. I have used :
shouldPlot = true;
switch nt
case 1
...
case 2
...
otherwise
shouldPlot = false;
...
end
if (shouldPlot)
figure (1);
plot(xx,f,xx,g);
hold on;
plot(xx, c);
legend('for f case1','for g case1','or f case2',
'for g case2','for c case 1','for c case2')
hold on
xlabel('...');
ylabel('...');
figure (2);
plot(xx,vel1,xx,vel2);
...
end
How can I show the lines names without legend is there another way?
Meva
Meva 2015년 3월 5일
Hi Michael, nothing show up does not give me an error.

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

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by