views:

11241

answers:

3

Usually when I plot in Matlab it always draws on the same figure. How to make it draw in a new figure? I know it is pretty elementary, but I'm not finding it on Google.

+7  A: 
figure;
plot(something);

or

figure(2);
plot(something);
...
figure(3);
plot(something else);
...

etc.

Federico Ramponi
+1  A: 

The other thing to be careful about, is to use the clf (clear figure) command when you are starting a fresh plot. Otherwise you may be plotting on a pre-existing figure (not possible with the figure command by itself, but if you do figure(2) there may already be a figure #2), with more than one axis, or an axis that is placed kinda funny. Use clf to ensure that you're starting from scratch:

figure(N);
clf;
plot(something);
...
Jason S
A: 

While doing "figure(1), figure(2),..." will solve the problem in most cases, it will not solve them in all cases. Suppose you have a bunch of matlab figures on your desktop and how many you have open varies from time to time before you run your code. Using the answers provided you will overwrite these figures, which you may not want. The easy workaround is to just use the command "figure" before you plot.

example(1): you have 5 figures on your desktop from a previous script you ran and you use

figure(1);
plot(...)

figure(2);
plot(...)`

you just plotted over the figures on your desktop. However the code

figure;
plot(...)

figure;
plot(...)

just created figures 6 and 7 with your desiderd plots and left your previous plots 1-5 alone.

matt

related questions