shouldPlot and switch case and legend and multiple figure error
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!