How do you plot two figures at the same time in Matlab? Every time I use surf() it plots over the old one. Also, how do you save the images so you can export them to MS word or powerpoint or something?
7 Answers
You can plot two figures in separate windows:
figure(1)
% do plotting
figure(2)
% do plotting
or in subplots:
figure(1)
subplot(1, 2, 1)
% do plotting
subplot(1, 2, 2)
% do plotting
For more info, you can see the MATLAB docs for the figure and subplot functions (in the help menu).
For printing the images to a file, see the documentation for the print function. Or just go to File -> Save As, and pick the image type you want.
Call figure before calling surf. figure opens a new figure window. When you call surf, it will plot into the currently selected figure.
You can copy-paste figures into Word or Powerpoint by using, in the figure window, the menu Edit->Copy Figure. If in, say Word, you click on the pasted figure and select 'ungroup', you can even go and edit the figure.
To save, you select 'Save as...' in the File-menu in the figure window. For Adobe Illustrator, save as .eps (works better than .ai).
Execute hold on to hold the current figure. New plots will be added to the existing plots. Use hold off to change it back to the previous behavior.
In addition to the print command (see Drew Hall's response), you can export to other formats via the File menu, or use the Copy Figure function of the edit menu. If you want to paste it into Word or Powerpoint, you might get a better result if you use "Paste Special" instead of normal Paste.