shouldPlot and switch case and legend and multiple figure error
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Michael Haderlein
am 5 Mär. 2015
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 Kommentare
Siehe auch
Kategorien
Mehr zu Legend finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!