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.MatFileReader System object

Read MAT file


The MatFileReader object reads V7.3 MAT files.

To read V7.3 MAT files:

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

  2. Call step to read the MAT file according to the properties of dsp.MatFileReader. 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) and y = obj() perform equivalent operations.


mfr = dsp.MatFileReader returns a System object, mfr, to read scalar stream data from a V7.3 MAT file.

mfr = dsp.MatFileReader(FILENAME,VARIABLENAME,FRAMESIZE) reads frames of MAT file data, using the specified file name, variable name, and frame size.

mfr = dsp.MatFileReader('PropertyName',PropertyValue,...) reads MAT file data with each specified property set to the specified value.

mfr = dsp.MatFileReader(FILENAME,VARIABLENAME,FRAMESIZE,'PropertyName',PropertyValue,...) reads frames of MAT file data, using the specified file name, variable name, and frame size, and other specified properties set to the specified values.



Name of MAT file from which to read

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.

Default: Untitled.mat


Name of the variable to read

Name of the variable stored in and read from the MAT file.

Default: x


Number of samples per output frame

Specify the number of elements (samples per frame) to read from the MAT file each time the step method is called.

Default: 1


isDoneEnd-of-file status
resetReset internal states of multimedia file reader to read from beginning of file
stepRead data from a variable in the MAT file
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).

Read a MAT file using the MatFileReader object.

filename = [tempname '.mat'];  % Create variable name
originalData = rand(40,2);
save(filename,'originalData','-v7.3'); % Write to MAT file
mfr = dsp.MatFileReader(filename,'VariableName',...
   'originalData','SamplesPerFrame', 4);  
while ~isDone(mfr)         % Stream data into MATLAB
    finalData = mfr();