Simulink.SimulationInput class

Package: Simulink
Superclasses:

Creates SimulationInput objects to make changes to a model for multiple or individual simulations

Description

The Simulink.SimulationInput object allows you to make changes to a model and run simulations with those changes. These changes are temporarily applied to the model. Through Simulink.SimulationInput object, you can change:

  • Initial state

  • Model parameters

  • Block parameters

  • External inputs

  • Variables

Through the Simulink.SimulationInput object, you can also specify MATLAB® functions to run at the start and the end of each simulation by using in.setPreSimFcn and in.setPostSimFcn, respectively.Simulink.SimulationInput does not support the ability to allow model references to have their own data dictionary.

Construction

in = Simulink.SimulationInput('modelName') creates a SimulationInput object for a model.

Input Arguments

expand all

Create a Simulink.SimulationInput object by passing the name of the model as an argument.

Example: in = Simulink.SimulationInput('cstr')

Properties

expand all

Name of the model for which the SimulationInput object is created.

Initial state of the model for a simulation specified as a Simulink.op.ModelOperatingPoint object.

External inputs added to the model for a simulation.

Block parameters of the model that are modified.

Variables of the model that are modified.

Model parameters of the model that are modified.

MATLAB function to run before the start of the simulation.

MATLAB function to run after each simulation.

Brief description of the simulation specified as a character array.

Methods

Method

Purpose

setModelParameter

Set model parameters to be used for a specific simulation through SimulationInput object.

setBlockParameter

Set block parameters to be used for a specific simulation through SimulationInput object.

setInitialState

Set initial state to be used for a specific simulation through SimulationInput object.

setExternalInput

Set external inputs for a simulation through SimulationInput object.

setVariable

Set variables for a simulation through SimulationInput object.

setPreSimFcn

Specify a MATLAB function to run before start of each simulation through SimulationInput object.

setPostSimFcn

Specify a MATLAB function to run after each simulation is complete through SimulationInput object.

applyToModel

Apply changes to the model specified through a SimulationInput object.

validate

Validate the contents of the SimulationInput object.

loadVariablesFromMATFile

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

Examples

collapse all

This example shows you how to create a SimulationInput object.

Open the model.

openExample('simulink/OpenTheModelExample');
open_system('ex_sldemo_househeat');
load_system('ex_sldemo_househeat')

Create a single SimulationInput object for a model.

model = 'ex_sldemo_househeat';
in = Simulink.SimulationInput(model);

This example shows you how to create an array of SimulationInput objects.

Create an array of SimulationInput objects by using the for loop.

model = 'vdp';
for i = 10:-1:1
   in(i) = Simulink.SimulationInput(model);
end

This example modifies the block parameters of a model through the SimulationInput object.

Open the model.

openExample('simulink/OpenTheModelExample');
open_system('ex_sldemo_househeat');
load_system('ex_sldemo_househeat')

Create a SimulationInput object for this model.

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

Modify block parameter.

in = in.setBlockParameter('sldemo_househeat/Set Point','Value','300');

Simulate the model.

out = sim(in)

This example shows how use Dataset objects to set external inputs with Simulink.SimulationInput objects.

Open the model

mdl = 'sldemo_mdlref_counter';
open_system(mdl);

Create a Dataset object for this model.

t = (0:0.01:10)';
ds = Simulink.SimulationData.Dataset;
ds = ds.setElement(1, timeseries(5*ones(size(t)),t)); % First element
ds = ds.setElement(2, timeseries(10*sin(t),t)); % Second element
ds = ds.setElement(3, timeseries(-5*ones(size(t)),t)); % Third element

Create a Simulink.SimulationInput object and set the external inputs

in = Simulink.SimulationInput('sldemo_mdlref_counter');
in = in.setExternalInput('ds.getElement(1),ds.getElement(2),ds.getElement(3)');

Add other remaining variables in the expressions. Ensure that the dataset is also on the SimulationInput object.

Simulate the model.

in = in.setVariable('ds',ds);

Simulate the model

out = parsim(in)
Introduced in R2017a