Plotting in Matlab

How do you draw two shapes at the same time in Matlab? Every time I use surf () it breaks back to the old one. Also, how do you save the images so that they can be exported to MS word or powerpoint or something?

+2


a source to share


7 replies


You can build two shapes in separate windows:


figure(1)
% do plotting
figure(2)
% do plotting

      

or in subheadings:




figure(1)
subplot(1, 2, 1)
% do plotting
subplot(1, 2, 2)
% do plotting

      

For more information, you can see the MATLAB docs for drawing functions and subtask (in the help menu).

To print images to a file, see the documentation for the print function. Or just go to File → Save As and select the desired image type.

+5


a source


Use the command in front of each scene / fixture / grid.

Example



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

      

+1


a source


Call figure

before call surf

. figure

opens a new shape window. When you call surf

it will display the currently selected digit.

You can copy the shapes to Word or Powerpoint using the Edit-> Copy Figure menu in the picture window. If in, say Word, you click on the inserted shape and select "ungroup", you can even go in and edit the shape.

To save, you choose "Save As ..." from the "File" menu in the picture window. For Adobe Illustrator save as .eps (works better than .ai).

+1


a source


As another small addition to the previous answers, you can print the shape directly to the clipboard using the command print -dmeta

. Then just paste into your Word or PowerPoint document. I found it very neat.

+1


a source


@kwatford If you are using hold all

, not hold on

then Matlab will use the next specific color and linestyle for this plot. check 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);

      

+1


a source


To create a new shape in a separate window, just say figure

. To export an image file, use the command print

with the appropriate option -d

to select the file format. For instance:

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

      

0


a source


Execute hold on

to hold the current drawing. New plots will be added to existing plots. Use hold off

to change it to the previous behavior.

In addition to the command print

(see Drew Hall's answer), you can export to other formats via the File menu, or use the Copy Picture function in the edit menu. If you want to paste it into Word or Powerpoint, you can get better results if you use "Paste Special" instead of the usual paste.

0


a source







All Articles