saveas(fig, filename)
saveas(fig, filename, formattype)
| Parameter | Description |
|---|---|
| fig | figure object. |
| filename | character vector or scalar string: destination filename. |
| formattype | character vector or scalar string: extension filename. |
saveas save figure to specific file format.
The explicit formattype takes precedence over the filename extension. Without an extension, PNG is selected and .png is appended. Desktop, web and headless modes use the same renderer and format registry.
Background: while the figure InvertHardcopy property is 'on' (the default), the exported background is white whatever the on-screen figure Color (light gray by default). Set InvertHardcopy to 'off' to export the on-screen figure color.
Vector formats use dedicated figure exporters:
| Option | Format | Extension |
|---|---|---|
| svg | Scalable Vector Graphics | .svg |
| Portable Document Format, full-page color |
Raster formats are encoded through the same registry as imwrite:
| Canonical option | Aliases | Extension |
|---|---|---|
| png | - | .png |
| jpg | jpeg, jfif | .jpg, .jpeg, .jfif |
| gif | - | .gif |
| webp | - | .webp |
| tiff | tif | .tiff, .tif |
| bmp | dib | .bmp, .dib |
| tga | - | .tga |
| pbm, pgm, ppm, pnm | - | .pbm, .pgm, .ppm, .pnm |
| pcx | - | .pcx |
x = -2:0.25:2;
y = x;
[X,Y] = meshgrid(x);
F = X.*exp(-X.^2-Y.^2);
surf(X,Y,F);
saveas(gcf(), [tempdir, 'svg-file.svg']);
saveas(gcf(), [tempdir, 'webp-file.webp']);
saveas(gcf(), [tempdir, 'bitmap-file.bmp']);
saveas(gcf(), [tempdir, 'document-file.pdf']);
close(gcf());
| Version | Description |
|---|---|
| 1.0.0 | initial version |
| 1.13.0 | tiff format added |
| 2.0.0 | shared desktop, web and headless export formats added |