papaduke
papaduke

Reputation: 21

Plotting in Matlab

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?

Upvotes: 2

Views: 9538

Answers (7)

mor22
mor22

Reputation: 1372

@kwatford If you use hold all rather than hold on then Matlab will use the next defined colour and linestyle for that plot. check out the difference between

figure(1);
plot(rand(100,1));
hold on ;
plot(rand(100,1)+2);

and

figure(2);
plot(rand(100,1));
hold all;
plot(rand(100,1)+2);

Upvotes: 1

yuk
yuk

Reputation: 19870

As another small addition to previous responses, you can print a figure directly to clipboard using print -dmeta command. Then just paste to Word or PowerPoint document. I found it very neat.

Upvotes: 1

ajduff574
ajduff574

Reputation: 2111

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.

Upvotes: 5

kenm
kenm

Reputation: 23905

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.

Upvotes: 0

Jonas
Jonas

Reputation: 74930

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).

Upvotes: 1

msemelman
msemelman

Reputation: 2937

Use the command figure before each plot/surf/mesh.

example

X = [1:5];
figure('Name', 'My plot');
plot(X, X+X);
figure('Name', 'My plot number 2');
plot(X, X + X + X);

Upvotes: 1

Drew Hall
Drew Hall

Reputation: 29047

To create a new figure in a separate window, just say figure. To export as an image file, use the print command with the appropriate -d option to select the file format. Like so:

figure;
plot(rand(100,1), rand(100, 1), 'r*');
print -dpng 'MyImage.png'

Upvotes: 0

Related Questions