loadVariablesFromMATFile

Load variables from MAT-file into a Simulink.SimulationInput object, in

Syntax

in = in.loadVariablesFromMATFile('filename')

Description

example

in = in.loadVariablesFromMATFile('filename') loads variables from the specified MAT-file into the Variables property of Simulink.SimulationInput.

Examples

collapse all

This example shows how to load variables from MAT-File into Simulink.SimulationInput object using the loadVariablesFromMATFile method.

Create a Simulink.SimulationInput Object

Create a Simulink.SimulationInput object for the example model.

mdl = 'ex_loadVar_sldemo_househeat';
in = Simulink.SimulationInput(mdl);
in
in = 

  SimulationInput with properties:

          ModelName: 'ex_loadVar_sldemo_househeat'
       InitialState: [0x0 Simulink.op.ModelOperatingPoint]
      ExternalInput: []
    ModelParameters: [0x0 Simulink.Simulation.ModelParameter]
    BlockParameters: [0x0 Simulink.Simulation.BlockParameter]
          Variables: [0x0 Simulink.Simulation.Variable]
          PreSimFcn: []
         PostSimFcn: []
         UserString: ''

Load Variables From MAT-File

Use the loadVariablesFromMATFile method of the Simulink.SimulationInput object.

in = in.loadVariablesFromMATFile('sldemo_househeat_data.mat');
in
in = 

  SimulationInput with properties:

          ModelName: 'ex_loadVar_sldemo_househeat'
       InitialState: [0x0 Simulink.op.ModelOperatingPoint]
      ExternalInput: []
    ModelParameters: [0x0 Simulink.Simulation.ModelParameter]
    BlockParameters: [0x0 Simulink.Simulation.BlockParameter]
          Variables: [1x25 Simulink.Simulation.Variable]
          PreSimFcn: []
         PostSimFcn: []
         UserString: ''

Simulate the Model

The model uses the loaded variables for simulation

out = sim(in)
out = 

  Simulink.SimulationOutput:
     sldemo_househeat_output: [1x1 Simulink.SimulationData.Dataset] 

          SimulationMetadata: [1x1 Simulink.SimulationMetadata] 
                ErrorMessage: [0x0 char] 

Input Arguments

collapse all

Name of MAT-file, specified as a character vector or string scalar.

Example: 'myFile'

Introduced in R2017a