Write MAT file
System object™ writes data to a V7.3 MAT file.
To write data to a V7.3 MAT file:
dsp.MatFileWriter object and set its properties.
Call the object with arguments, as if it were a function.
To learn more about how System objects work, see What Are System Objects?
returns a MAT file
writer System object,
mfw = dsp.MatFileWriter
mfw, that writes data to a V7.3 MAT file.
returns a MAT file writer System object with the
mfw = dsp.MatFileWriter(
Filename property set to
fname and the
VariableName property set to
returns a MAT file writer System object with each specified property set to the specified value. Unspecified
properties have default values.
mfw = dsp.MatFileWriter(
Unless otherwise indicated, properties are nontunable, which means you cannot change their
values after calling the object. Objects lock when you call them, and the
release function unlocks them.
If a property is tunable, you can change its value at any time.
For more information on changing property values, see System Design in MATLAB Using System Objects.
Filename— Name of MAT file to write
'Untitled.mat'(default) | character vector | string scalar
Specify the name of a MAT file as a character vector or a string scalar. Specify the full path for the file only if the file is not on the MATLAB® path.
VariableName— Name of variable to write
'x'(default) | character vector | string scalar
Name of the variable to which to write, returned as a character vector or a string scalar. This variable is stored in the MAT file. You cannot overwrite a variable that is already in an existing MAT file.
data— Data to be written to MAT file
Data to be written to the MAT file, specified as a scalar, vector, or a matrix. The data can be an N-dimensional array.
To use an object function, specify the
System object as the first input argument. For
example, to release system resources of a System object named
Note: This example runs only in R2016b or later. If you are using an earlier release, replace each call to the function with the equivalent
step syntax. For example, myObject(x) becomes step(myObject,x).
First, create a variable name.
filename = [tempname '.mat'];
Next, write that variable to a MAT-file.
mfw = dsp.MatFileWriter(filename,'VariableName','originalData'); for i = 1:10 originalData = rand(4,2); mfw(originalData); end release(mfw); % This will close the MAT file
Finally, load the variable back into MATLAB.
data = load(filename,'originalData');
Plot the data.