RunMat
  • Pricing
RunMat
GitHub
GitHub
Sign inTry in browser
DesktopRuntimePhysicsCADAdministrationAgent

Get RunMat updates

New releases, guides and examples.

Product+
  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download
Math+
  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting
Physics+
  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA
Industries+
  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance
Learn+
  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students
Compare+
  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons
Company+
  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms

Product

  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download

Math

  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting

Physics

  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA

Industries

  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance

Learn

  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students

Compare

  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons

Company

  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms
GitHubXLinkedIn

© Dystr, Inc. · RunMat v0.7.1, Nov 17, 2026

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.

/
See all docs
Builtin Reference
    • load
    • matfile
    • matlab.io.MatFile.subsasgn
    • matlab.io.MatFile.subsref
    • save

save — Save workspace values to a Level-5 MAT-file.

save(filename) writes the selected caller workspace to an uncompressed Level-5 MAT-file. Variable names, string arrays of names, -struct, -regexp, and -append choose what is written. The MATLAB-compatible form is a zero-output statement; capturing the double-zero success status is a RunMat extension.

Syntax

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

Inputs

filename
Type
StringScalar
Required
Yes
Default
"matlab.mat"
Description
Level-5 MAT-file path.
varName
Type
StringScalar
Required
Variadic
Description
Whole variable names.
option
Type
StringScalar
Required
Yes
Description
Supported MAT selection or save option.
pattern
Type
StringScalar
Required
Variadic
Description
Regular-expression patterns.
NameTypeRequiredDefaultDescription
filenameStringScalarYes"matlab.mat"Level-5 MAT-file path.
varNameStringScalarVariadic—Whole variable names.
optionStringScalarYes—Supported MAT selection or save option.
patternStringScalarVariadic—Regular-expression patterns.

Returns

status
Type
NumericScalar
Description
Double zero on success.
NameTypeDescription
statusNumericScalarDouble zero on success.

Errors

RunMat:save:InvalidArgument
When
Inputs are not a supported save form.
Message
save: invalid argument
RunMat:save:InvalidOption
When
A save option or value is invalid.
Message
save: invalid option
RunMat:save:Selection
When
A workspace variable or field cannot be resolved.
Message
save: variable selection failed
IdentifierWhenMessage
RunMat:save:InvalidArgumentInputs are not a supported save form.save: invalid argument
RunMat:save:InvalidOptionA save option or value is invalid.save: invalid option
RunMat:save:SelectionA workspace variable or field cannot be resolved.save: variable selection failed
RunMat:save:FilenameThe MAT path is invalid.save: invalid filename
RunMat:save:IoMAT output cannot be written.save: MAT-file I/O failure
RunMat:save:UnsupportedThe mode or value cannot be saved.save: unsupported operation
RunMat:save:WorkspaceWorkspace state is unavailable.save: workspace state unavailable

Paths and selection

Bare save() writes matlab.mat, or RUNMAT_SAVE_DEFAULT_PATH when that environment override is set. Paths without an extension gain .mat; parent directories must exist. Explicit names select workspace variables. -struct writes selected fields as individual variables, and -regexp selects matching workspace names. Missing names, unmatched patterns, and malformed options reject with typed errors.

-append reads an existing Level-5 file, merges the new entries by name, and writes a refreshed file. A new value replaces an existing value of the same name. ASCII/text format switches such as -ascii and -double are not accepted.

Values

Dense real/complex single and double arrays; all eight signed/unsigned integer classes; logical, character, string, cell, struct, and real sparse arrays retain their available shapes and storage semantics. RunMat writes typed Level-5 object records and may invoke registered saveobj hooks. Function handles and opaque graphics handles are unsupported and raise errors.

Resident array values are gathered from their owning provider before encoding. The MAT file holds host bytes; saving does not mutate the original resident value. Large arrays, append, object callbacks, and full-file encoding may require substantial host memory.

Execution

The selected filesystem provider and relative path are captured before the file operation. Writes replace the path through that provider; MAT encoding does not create a device kernel. File writing is not a multi-file transaction and an operational error is not retried as a different route.

Examples

Save the entire workspace

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

Save selected variables

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

Save struct fields as variables

x = 1:5;
y = [5 4 3 2 1];
opts = struct('output', y, 'answer', x);
save('opts.mat', '-struct', 'opts')

Select names by regular expression

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

Append another variable

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

Select names with a string array

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

Save a resident array

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

Reject a missing workspace name

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?⌄

Uncompressed Level-5 MAT files. Dense available numeric classes, exact integers, and real sparse matrices use Level-5 class tags; HDF5-backed v7.3 output is not supported.

Is -append supported?⌄

Yes for supported Level-5 content. The existing file is decoded, entries are merged by name, and a new Level-5 file is written. A duplicate name is replaced by the new value.

Do -ascii or -double work?⌄

No. The current writer uses the Level-5 MAT format only.

Are objects or function handles saved?⌄

RunMat typed Level-5 object records and registered saveobj hooks are supported. Function handles are rejected.

Does save return a value?⌄

The MATLAB-compatible call is a zero-output statement. With RunMat extensions enabled, one captured output is double zero on success.

How do I change the bare-save filename?⌄

Set RUNMAT_SAVE_DEFAULT_PATH. With no explicit filename, save uses that path instead of matlab.mat.

Are parent folders created?⌄

No. The parent folder must already exist, or the filesystem provider returns an error.

Related Io functions

Mat

load · matfile · matlab.io.MatFile.subsasgn · matlab.io.MatFile.subsref

Net

accept · read · readline · tcpclient · tcpserver · write

Repl Fs

addpath · cd · copyfile · delete · dir · exist · fileattrib · fileparts · filesep · fullfile · genpath · getenv · getpref · isenv · isfile · isfolder · ispref · ls · matlabroot · memmapfile · memmapfile.subsasgn · memmapfile.subsref · 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 · getvaropts · parquetDatastore · parquetinfo · parquetread · readcell · readmatrix · readtable · readtimetable · setvaropts · setvartype · spreadsheetImportOptions · writecell · writematrix · writetable · writetimetable · xlsread · xlswrite

Audio

audioinfo · audioread

Io

clc · diary · disp · display · format · input

Data

commit · data.copy · data.create · data.delete · data.exists · data.export · data.import · data.inspect · data.list · data.move · data.open · DataArray.chunk_shape · DataArray.codec · DataArray.dtype · DataArray.fill · DataArray.name · DataArray.rank · DataArray.read · DataArray.resize · DataArray.shape · DataArray.write · Dataset.array · Dataset.arrays · Dataset.attrs · Dataset.begin · Dataset.get_attr · Dataset.has_array · Dataset.id · Dataset.path · Dataset.refresh · Dataset.set_attr · Dataset.set_attrs · Dataset.snapshot · Dataset.version · DataTransaction.abort · DataTransaction.commit · DataTransaction.create_array · DataTransaction.delete_array · DataTransaction.fill · DataTransaction.id · DataTransaction.resize · DataTransaction.set_attr · DataTransaction.set_attrs · DataTransaction.status · DataTransaction.write

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

Source you can read

Every RunMat function's source is public. 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 a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/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
  • Paths and selection
  • Values
  • Execution
  • Examples
  • Save the entire workspace
  • Save selected variables
  • Save struct fields as variables
  • Select names by regular expression
  • Append another variable
  • Select names with a string array
  • Save a resident array
  • Reject a missing workspace name
  • Using save with coding agents
  • FAQ
  • Related Io functions
  • Mat
  • Net
  • Repl Fs
  • Tabular
  • Audio
  • Io
  • Data
  • Filetext
  • Archive
  • Hdf5
  • Import
  • Json
  • Http
  • Source you can read
  • About RunMat