Several graphs in 1 cycle, each iteration adds a line to each digit

Trying to develop the following in Matlab:

** loop start; y(:,i) = function of x; z(:,i) = function of x; plot(x,y(:,i)) on figure 1, hold all; plot(x,z(:,i)) on figure 2, hold all; ** loop end; add title, legend, etc for figure 1 (NB: we have multiple lines); add title, legend, ets for figure 2 (NB: same, have multiple lines for the legend);` 

I tried several combinations without much luck. Managed to get 2 digits, but only the 2nd displays a few lines, not the first. And he cannot understand how to add legends to these 2 correctly.

+4
source share
2 answers

Keep a handle to each shape and each axis object:

 fh1 = figure; hold all; ah1 = gca; fh2 = figure; hold all; ah2 = gca; for i=1:N y(:,i) = function of x; z(:,i) = function of x; plot(ah1, x, y(:,i)); %# tell it which axis to use (ah1) plot(ah2, x, z(:,i)); %# (ah2) end legend(ah1, ...) %# legend options here legend(ah2, ...) %# and the other legend %# note: you can set figure properties for each using fh1, fh2 handles. 
+4
source

You can do it:

 figHandle1 = figure(1); figHandle2 = figure(2); 

Then, when you want to build on this shape, do the following:

 figure(figHandle1) %Plot on figure 1 %ie plot(someStuff) figure(figHandle2) %Plot on figure 2 

And the same for the title and material, you need to determine which figure to do:

 figure(handle); 

Hope this helps.

0
source

All Articles