This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

dsp.MatFileWriter System object

Write MAT file


The MatFileWriter object writes data to a V7.3 MAT file.

To write data to a V7.3 MAT file:

  1. Define and set up your System object™. See Construction.

  2. Call step to write data according to the properties of dsp.MatFileWriter. The behavior of step is specific to each object in the toolbox.


Starting in R2016b, instead of using the step method to perform the operation defined by the System object, you can call the object with arguments, as if it were a function. For example, y = step(obj,x) and y = obj(x) perform equivalent operations.


mfw = dsp.MatFileWriter returns a MAT file writer System object, mfw, that writes data to a V7.3 MAT file.

mfw = dsp.MatFileWriter('PropertyName',PropertyValue,...) returns a MAT file writer System object, mfw, with each specified property set to the specified value.

mfw = dsp.MatFileWriter(FILENAME,'PropertyName',PropertyValue,...) returns a MAT file writer System object, mfw, with Filename property set to FILENAME and other specified properties set to the specified values.



Name of MAT file to write

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. The default file name is Untitled.mat.


Name of the variable to write

Name of the variable to which to write. This variable is stored in the MAT file. The default variable name is x. You cannot overwrite a variable that is already in an existing MAT file.


stepWrite one frame of MAT file data
Common to All System Objects

Allow System object property value changes


expand all

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);
release(mfw); % This will close the MAT file

Finally, load the variable back into MATLAB.

data = load(filename, 'originalData');

Plot the data.


Introduced in R2012b