Simulink.io.MatFile - Read data in MAT file format - MATLAB (original) (raw)

Main Content

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

These methods specialize standard MATLABĀ® operators and functions for objects in this class.

isFileSupported This method always returns true because it operates only on data in the MAT file.
getFileTypeDescription This method returns the MAT file reader description for MAT files containing data with loading and logging signal formats that SimulinkĀ® supports.

Examples

collapse all

Read data in MAT file format from the filefoo.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 namedbar.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