matlab.io.saveVariablesToScript
Save workspace variables to MATLAB script
Syntax
Description
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 are too large or 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.
Examples
Input Arguments
Name-Value Arguments
Output Arguments
Limitations
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
Missing values in string arrays
If you have Simulink®, you can use matlab.io.saveVariablesToScript
to save the
variables that your models use. If a Simulink data object in the workspace contains a large array, the function saves only the
numeric value to a MAT file and writes the rest of the data object to a MATLAB file.
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. 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.