Main Content


Read MAT file


The dsp.MatFileReader System object™ reads V7.3 MAT files.

To read V7.3 MAT files:

  1. Create the dsp.MatFileReader object and set its properties.

  2. Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects?



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

mfr = dsp.MatFileReader(fname,vname,framesize) reads frames of MAT file data, using the specified file name, variable name, and frame size.


mfr = dsp.MatFileReader(___,Name,Value) reads MAT file data with each specified property set to the specified value.


expand all

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.

Name of the MAT file from which to read, specified 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.

Name of the variable to read from the MAT file, specified as a character vector or a string scalar.

Number of samples per output frame to read from the MAT file on each call to the object algorithm, specified as a positive, integer-valued scalar.




data = mfr() reads data from a specified variable stored in a MAT-file. The variable is assumed to be N-dimensional and a MATLAB built-in data type. The data is read into MATLAB by reading along the first dimension.

Output Arguments

expand all

Data read from the MAT file, returned as a scalar, vector, or a matrix. The data can be an N-dimensional array.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Object Functions

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 obj, use this syntax:


expand all

isDoneEnd-of-data status
stepRun System object algorithm
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object


collapse all

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();

Version History

Introduced in R2012b