lettura simple

Saving a Plot as a File in Matlab

In this tutorial, I'll show you how to save the image of a plot created in Matlab as a digital file.

It's simple and fun, so let's get started.

Imagine we've just conjured up a beautiful plot using the peaks() command.

>> peaks()

This nifty little function generates a mesmerizing 3D plot of a two-variable function right before our eyes.

example of 3D graph

Now, let's capture this piece of art as an SVG image file.

>> print -dsvg example1.svg

The print function creates the file example1.svg in the Matlab working directory.

To save our creation as a PNG image, we simply modify the command.

>> print -dpng example1.png

Alternatively, you can save a plot using the saveas() function.

>> saveas(1, "example2.png");

The end result is the same.

You can find the files you just created in the Matlab working directory on your computer or in the cloud if you're using Matlab online.

Image files in the Matlab working directory

The files you just created are image files (PNG or SVG) and can be opened with any graphic software (e.g., Photoshop, Gimp, etc.).




Report a mistake or post a question




FacebookTwitterLinkedinLinkedin