saveas

Save a figure to a specific file.

Syntax

saveas(h, file_name)

saveas(h, file_name, file_format)

saveas(..., [width height])

Inputs

h
The handle of a figure.
Type: double | integer
Dimension: scalar
file_name
The name of the output file.
Type: string
Dimension: scalar
file_format
The format of the output file. Options include 'PNG', 'JPG', 'JPEG', 'BMP', and 'SVG'. If omitted, the format will be extracted from the file name. The default file format is 'PNG'.
Type: string
Dimension: scalar
width, height
The dimensions of the exported image in pixels. If omitted, the exported image will have the same dimensions as the figure window.
Type: integer
Dimension: scalar

Examples

f=figure;
plot(rand(1,100));
saveas(f, 'demo1');
f=figure;
plot(rand(1,100));
saveas(f, 'demo2.bmp');
f=figure;
plot(rand(1,100));
saveas(f, 'demo3', 'bmp');
f=figure;
plot(rand(1,100));
saveas(f, 'demo4', [500 500]]);
f=figure;
plot(rand(1,100));
saveas(f, 'demo5', 'jpg', [1280 720]);