saveas
Saves a figure or Simulink model to a file in a chosen format.
Category: Graphics > Printing and Saving
Syntax
saveas(fig, filename)
Saves fig; the format is taken from the extension in filename.
saveas(fig, filename, formattype)
Forces a format such as 'png', 'jpg', 'svg', 'pdf', 'fig' or 'epsc'.
Description
saveas is a quick way to dump a figure as it appears, including the surrounding margins. For control over resolution and cropping, exportgraphics or print is better. The 'fig' format stores an editable figure.
Input arguments
fig- Figure handle, for example
gcf. filename- Output name, with or without extension.
formattype- Format name as text.
Example
Save the current figure
plot(1:5)
try
saveas(gcf, 'myplot.png');
disp('saved myplot.png')
catch
disp('needs the editor renderer')
end
Output
needs the editor renderer
In the app the file is written and the first message is shown.
Notes
Writing files needs the MatLivre editor's renderer, and .fig files are not supported; use PNG, JPG or SVG. The headless runtime reports an error, which the example catches.