print — Export figures to files in MATLAB and RunMat.
print exports the active or specified figure to files. Device tokens, resolution options, and argument forms follow MATLAB-style print semantics in RunMat.
Syntax
ok = print(filename, '-dpng')
ok = print(filename, '-dpng', '-r300')
ok = print(fig, filename, '-dpng')
ok = print('-dpng', filename)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
args | Any | Variadic | — | Optional figure handle, filename, device token such as '-dpng', and resolution token such as '-r300'. |
Returns
| Name | Type | Description |
|---|---|---|
ok | LogicalArray | True when the export completed. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:print:InvalidInput | Arguments are missing, malformed, or cannot be interpreted as a supported print form. | print: invalid input arguments |
RunMat:print:UnsupportedDevice | The requested output device is not supported by the active exporter. | print: unsupported output device |
RunMat:print:InvalidOption | A print option token is unsupported or invalid. | print: invalid option |
RunMat:print:RenderFailed | The figure renderer fails while serializing the figure. | print: figure export failed |
RunMat:print:IoFailure | The exported bytes cannot be written to the target file. | print: file I/O failed |
| — | Internal runtime control-flow or conversion fails. | print: internal error |
How print works
print(filename, '-dpng')writes PNG bytes tofilename. If the name has no.pngextension, RunMat appends one.print(filename, '-dpng', '-rN')scales the export dimensions from the default 800 by 600 canvas usingNDPI relative to RunMat's 150 DPI default.print(fig, filename, '-dpng')exports the specified figure handle instead of the active figure.- Command-style argument order is accepted when RunMat parses command calls into string arguments, such as
print -dpng plot.png. - PDF, EPS, and SVG device tokens are recognized but return a clear unsupported-device error until those exporters are implemented.
Does RunMat run print on the GPU?
No numeric GPU kernels are launched for print itself.
The PNG exporter first attempts the interactive GPU render path and falls back to CPU rasterization when headless GPU initialization is unavailable.
The builtin writes PNG bytes through RunMat's filesystem layer, so output storage is host or virtual-filesystem backed.
GPU memory and residency
print is an I/O sink and returns a host logical status. Filename and option arguments are gathered before parsing. GPU-resident plot data already captured in figure state may still be consumed by the plotting renderer without forcing user-visible gathers when the shared WGPU export path is available.
Examples
Export the active figure to a PNG file
x = 0:0.1:2*pi;
plot(x, sin(x));
print("sine_plot", "-dpng");Export at a higher resolution
x = 0:0.1:1;
plot(x, x.^2, "LineWidth", 2);
print("quadratic_plot", "-dpng", "-r300");Export a specific figure handle
fig = figure();
plot(1:5, [1 4 2 5 3]);
print(fig, "explicit_handle_plot.png", "-dpng");Command-style device order
plot(1:4, [1 3 2 4]);
print -dpng command_style_plot.pngUsing print with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how print changes the result.
Run a small print example, explain the result, then change one input and compare the output.
FAQ
Which formats does print support?⌄
PNG is supported today with -dpng. RunMat recognizes PDF, EPS, and SVG device tokens, but they return an unsupported-device error until those exporters are available in the rendering stack.
Where does the file go in the browser?⌄
The PNG is written through RunMat's filesystem provider. In the sandbox this is usually the in-memory or IndexedDB-backed virtual filesystem, and the host can expose the file as a download artifact.
Does -r300 change the figure data?⌄
No. It only changes the pixel dimensions used for export. The plot data and graphics handles remain unchanged.
Related Plotting functions
More plotting resources
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how print is executed, line by line, in Rust.
- View the source for print in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.