Save workspace variables to MATLAB script
matlab.io.saveVariablesToScript(
saves
variables in the current workspace to a MATLAB® script named filename
)filename.m
.
The filename can include the .m
suffix. If you
do not include it, the function adds it when it creates the file.
Variables that MATLAB cannot generate code for are saved
to a MAT-file named filename.mat
.
If a file with the same name already exists, it is overwritten.
matlab.io.saveVariablesToScript(
uses
additional options specified by one or more filename
,Name,Value
)Name,Value
pair
arguments.
matlab.io.saveVariablesToScript
does
not save the following variables to a MATLAB script or a MAT-file.
Java objects
.NET objects
Python objects
matlab.io.saveVariablesToScript
saves
the following variables only to a MAT-file.
MATLAB objects
Function handles
Anonymous functions
If you have Simulink®, you can use matlab.io.saveVariablesToScript
to
save the variables that your models use. However, if you save many
variables, the generated MATLAB file can contain many lines of
code and take a long time to execute. To avoid the long execution
time, consider these alternatives:
Permanently store variables in a data dictionary instead
of using Simulink.saveVars
. A data dictionary
also provides more tools for managing variables. See Determine Where to Store Variables and Objects for Simulink Models (Simulink).
Save variables in a MAT-file by using the save
function.