RunMat
  • Pricing
RunMat
GitHub
GitHub
DownloadSign InTry in Browser
DesktopRuntimeServer
RunMat

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact

Explore

  • RunMat for academia
  • RunMat vs MATLAB Online
  • Benchmarks

Get product updates and release notes from the RunMat team.

© 2026 Dystr · Made withfor the scientific community.

RunMat™ is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

LicensePrivacy
/
See all docs
Builtin Reference
    • load
    • matfile
    • save

save — Persist variables from the current workspace to a MATLAB-compatible MAT-file.

save writes variables from the current workspace to a MAT-file on disk. It supports MATLAB-compatible variable selection, struct-field extraction, and option handling such as '-struct' and '-regexp'.

Syntax

status = save()
status = save(filename)
status = save(filename, varName1, varName2, ...)
status = save(filename, "-struct", structVar, field1, ...)
status = save(filename, "-regexp", pattern1, ...)

Inputs

NameTypeRequiredDefaultDescription
filenameStringScalarYes"matlab.mat"MAT-file output path.
varNameStringScalarVariadic—Workspace variable names to persist.
filenameStringScalarNo"matlab.mat"MAT-file output path.
optionStringScalarYes"-struct"Struct field export option.
structVarStringScalarYes—Workspace struct variable name.
optionStringScalarYes"-regexp"Regex selection option.
patternStringScalarVariadic—Regex patterns matched against workspace variable names.

Returns

NameTypeDescription
statusNumericScalarZero status code on success.

Errors

IdentifierWhenMessage
RunMat:save:InvalidArgumentArguments do not match supported save invocation forms.save: invalid argument
RunMat:save:InvalidOptionOption token or option value is invalid.save: invalid option
RunMat:save:SelectionRequested variables or struct fields cannot be resolved.save: variable selection failed
RunMat:save:FilenameFilename is invalid or cannot be normalized.save: invalid filename
RunMat:save:IoMAT-file cannot be written or finalized.save: MAT-file I/O failure
RunMat:save:UnsupportedUnsupported save mode or value type is requested.save: unsupported operation
RunMat:save:WorkspaceWorkspace state is unavailable.save: workspace state unavailable

How save works

  • save with no arguments writes every variable from the caller workspace to matlab.mat in the current working directory. Set RUNMAT_SAVE_DEFAULT_PATH to override the default target when no filename is supplied.
  • save filename writes all workspace variables to filename. If the supplied name has no extension, .mat is added automatically. Paths are resolved relative to the current directory, and parent folders must already exist.
  • save(filename, 'A', 'B') writes only the listed variables. String arrays or cell arrays of character vectors are accepted to specify multiple names.
  • save(filename, '-struct', 'S') saves each field of struct S as a separate variable. Provide additional field names ('field1', 'field2') to restrict the set.
  • save filename -regexp '^foo' 'bar$' saves every variable whose name matches any of the supplied regular expressions.
  • Existing files are overwritten unless -append is specified. With -append, RunMat reads the existing supported MAT variables, merges in the newly selected variables, and rewrites the file so newer variables replace older variables with the same name.
  • Numeric/text format flags outside the MAT-file path (for example -ascii, -double, -v6, -v7.3) are not supported yet and report descriptive option errors.
  • Function handles and opaque graphics handles raise descriptive errors. Numeric, logical, character, string, cell, scalar struct, real sparse data, and RunMat objects are stored using MATLAB Level-5 MAT-file layout. Objects are written through saveobj when registered and otherwise through an internal scalar-struct object envelope.
  • save returns 0 so scripts can treat it as a statement, matching MATLAB's void behaviour.

Does RunMat run save on the GPU?

save acts as a residency sink. Before serialising, RunMat gathers any GPU-resident tensors through the active acceleration provider so the MAT-file contains host data. Fusion groups terminate at this builtin and providers do not require custom hooks.

GPU memory and residency

No manual action is required. save gathers gpuArray inputs automatically before writing the MAT-file. This matches MATLAB's behaviour when gpuArray variables are passed to save.

Examples

Save the entire workspace

x = 42;
y = magic(3);
save('session.mat')

Save selected variables only

a = rand(1, 3);
b = eye(2);
c = "ignore me";
save('selection.mat', 'a', 'b')

Save struct fields as individual variables

x = 1:5;
y = rand(1, 5);
opts = struct('output', y, 'answer', x);
save('opts.mat', '-struct', 'opts')

Select variables by regular expression

result_acc = 1:3;
result_tmp = 4:6;
scratch = pi;
save('filtered.mat', '-regexp', '^result_', 'tmp$')

Append variables to an existing MAT-file

save('session.mat', 'x')
y = 2*x;
save('session.mat', 'y', '-append')

Save multiple names using a string array

names = ["result_acc", "scratch"];
save('mixed.mat', names)

Save GPU arrays without manual gather

G = gpuArray(magic(3));
save('gpu.mat', 'G')

Error when a variable is missing

save('bad.mat', 'missing')

Using save with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how save changes the result.

Run a small save example, explain the result, then change one input and compare the output.

FAQ

Which MAT-file version is generated?⌄

RunMat writes uncompressed Level-5 (MATLAB 5.0) MAT-files, compatible with MATLAB R2006b and later as well as NumPy/Scipy readers. Numeric arrays preserve RunMat's available numeric classes (double, single, uint8, and uint16 tensors plus integer scalars), and real sparse matrices use standard mxSPARSE storage.

Is -append supported?⌄

Yes for supported MAT-file content. RunMat decodes the existing MAT-file, merges the selected variables, and writes a fresh Level-5 MAT-file. If a variable name already exists, the new value replaces the previous value, matching MATLAB's practical append workflow.

Do text options like -ascii or -double work?⌄

These legacy text/binary format switches are not supported. RunMat favours MATLAB's default MAT-file format.

Are objects or function handles saved?⌄

Objects are supported through RunMat's object serialization envelope and registered saveobj hooks. Function handles remain unsupported and raise an error.

Does save return a value?⌄

Yes. The builtin returns 0, which MATLAB treats as an empty output, so scripts can ignore the return value just as they do in MATLAB.

How do I change the default filename used by bare save?⌄

Set the environment variable RUNMAT_SAVE_DEFAULT_PATH before launching RunMat. When save is called without explicit filename arguments, the builtin writes to that path instead of matlab.mat.

Does save create parent directories automatically?⌄

No. Parent folders must already exist; otherwise the builtin raises an error from the host filesystem.

Related Io functions

Mat

load · matfile

Net

accept · read · readline · tcpclient · tcpserver · write

Repl Fs

addpath · cd · copyfile · delete · dir · exist · fileattrib · fileparts · fullfile · genpath · getenv · getpref · isenv · isfile · isfolder · ispref · ls · matlabroot · memmapfile · mkdir · movefile · open · opentoline · path · pathsep · pcode · pwd · readstruct · rehash · restoredefaultpath · rmdir · rmpath · run · savepath · setenv · setpref · system · tempdir · tempname · uigetdir · uigetfile · uiputfile · unsetenv · userpath · what · winqueryreg · xmlread · xmlwrite

Tabular

arrayDatastore · csvread · csvwrite · detectImportOptions · dlmread · dlmwrite · fileDatastore · parquetDatastore · parquetinfo · parquetread · readcell · readmatrix · readtable · readtimetable · spreadsheetImportOptions · writecell · writematrix · writetable · writetimetable · xlsread · xlswrite

Audio

audioinfo · audioread

Io

clc · diary · disp · display · format · input

Filetext

fclose · feof · fgetl · fgets · fileread · filewrite · fopen · fprintf · fread · frewind · fwrite · readlines · writelines

Archive

gunzip · gzip · unzip

Hdf5

h5disp · h5info · h5read · h5write · h5writeatt · hdf5info · hdf5read · hdf5write

Import

importdata · textscan

Json

jsondecode · jsonencode

Http

sendmail · urldecode · urlencode · weboptions · webread · websave · webwrite

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how save is executed, line by line, in Rust.

  • View the source for save 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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • How save works
  • Does RunMat run save on the GPU?
  • GPU memory and residency
  • Examples
  • Save the entire workspace
  • Save selected variables only
  • Save struct fields as individual variables
  • Select variables by regular expression
  • Append variables to an existing MAT-file
  • Save multiple names using a string array
  • Save GPU arrays without manual gather
  • Error when a variable is missing
  • Using save with coding agents
  • FAQ
  • Related Io functions
  • Mat
  • Net
  • Repl Fs
  • Tabular
  • Audio
  • Io
  • Filetext
  • Archive
  • Hdf5
  • Import
  • Json
  • Http
  • Open-source implementation
  • About RunMat