Main Content

loadAVariableImpl

Class: Simulink.io.FileType
Namespace: Simulink.io

Load specified variable from MAT-file

Since R2020a

Syntax

varOut = loadAVariableImpl(MATfile,varName)

Description

varOut = loadAVariableImpl(MATfile,varName) loads the specified variable from the MAT-file.

Input Arguments

expand all

File name of the MAT-file that contains signals to load, specified as a character array.

Data Types: char

Variable name to load, specified as a character array.

Data Types: char

Output Arguments

expand all

Found variables to load, returned as a cell array of signal variables of supported types. For more information on supported types, see Choose a Base Workspace and MAT-File Format.

Examples

expand all

Subclass FileType class and implement loadAVariableImpl method.

classdef MySignalMatFile < Simulink.io.FileType

Implement the static method loadAVariableImpl.

methods
        
        function structOut = loadAVariableImpl(obj,varName)
            
            % Assume loading a variable from a MAT-file.
            data = load(obj.FileName,varName);            
            
            if isempty(fieldnames(data))
                error([varName ' was not found on the file.']);
            end
                
            if isSimulinkSignalFormat(data.(varName))
                structOut.(varName) = ...
                    data.(varName);
            else
                error([varName ' is not a Simulink signal format.']);
            end
            
        end
    end

Version History

Introduced in R2020a