Main Content

loadVariablesFromMATFile

Load variables from MAT file into Simulink.SimulationInput object

Description

simIn = loadVariablesFromMATFile(simIn,filename) loads variables from the MAT file filename into the Variables property of the Simulink.SimulationInput simIn.

simIn = loadVariablesFromMATFile(simIn,filename,'Append', 'on') loads variables from the MAT file filename into the Variables property of the Simulink.SimulationInput simIn, while adding to the existing variables in the Variables property instead of replacing them.

example

Examples

collapse all

Load variables from a MAT file into a Simulink.SimulationInput object using the loadVariablesFromMATFile function.

Create a Simulink.SimulationInput object for the model.

mdl = "ex_loadVar_sldemo_househeat";
simIn = Simulink.SimulationInput(mdl);

Use the loadVariablesFromMATFile function to load variables from a MAT file into the Variables property of the Simulink.SimulationInput object.

simIn = loadVariablesFromMATFile(simIn,"sldemo_househeat_data.mat")
simIn = 
  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: ''
    VariantConfiguration: ''

The simulation uses the variables loaded into the Simulink.SimulationInput object.

out = sim(simIn);

Input Arguments

collapse all

Simulation inputs and configuration, specified as a Simulink.SimulationInput object.

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

Example: 'myFile'

Option to append new loaded variables to existing variables in Simulink.SimulationInput object, specified as 'off' or 'on'

Output Arguments

collapse all

Simulation configuration with variables from MAT file added, returned as a Simulink.SimulationInput object.

Version History

Introduced in R2017a