This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

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