Main Content

Simulink.io.MatFile Class

Namespace: Simulink.io

Read data in MAT file format

Since R2021a

Description

Simulink.io.MatFile inherits from the Simulink.io.FileType base class. The class reads data formatted in a format used by MAT files. To import data from a MAT file, use this class.

classdef MatFile < Simulink.io.FileType

The Simulink.io.MatFile class is a handle class.

Class Attributes

Abstract
false
HandleCompatible
true

For information on class attributes, see Class Attributes.

Properties

expand all

MAT file reader, specified as a character array.

Attributes:

GetAccess
public
SetAccess
public

Data Types: char | string

Methods

expand all

Examples

collapse all

Read data in MAT file format from the file foo.mat.

fileName = 'foo.mat';
aReader = Simulink.io.MatFile(fileName);
resultOfWhos = whos(aReader);

Load the reader, which has no inputs.

varsOnFileStruct = load(aReader);

Load one variable.

var = loadAVariable(aReader,'ts');

Import all the variables from the MAT file, foo.mat.

importedVars = import(aReader);

Export the dataset to a MAT file named bar.mat.

ds = Simulink.SimulationData.Dataset;
ds = ds.addElement(timeseries([1:10]',[1:10]'),'Signal1');
ds = ds.addElement(timeseries([1:10]',[11:20]'),'Signal2');
ds = ds.addElement(timeseries([1:10]',[21:30]'),'Signal3');

filePath = 'bar.mat';
didWrite = aReader.export(filePath,{'ds'},{ds},0);

Version History

Introduced in R2021a