Main Content

Simulink.SimulationInput class

Package: Simulink
Superclasses:

Creates SimulationInput objects to make changes to 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. Using a 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 the setPreSimFcn function and the setPostSimFcn.

Construction

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

Input Arguments

expand all

Name of model, specified as a string or a character vector.

Example: simIn = 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 or a string.

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

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';
simIn = Simulink.SimulationInput(model);

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

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

model = 'vdp';
for k = 10:-1:1
   simIn(k) = 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';
simIn = Simulink.SimulationInput(mdl);

Modify block parameter.

simIn = setBlockParameter(simIn,'ex_sldemo_househeat/Set Point',...,
   'Value','300');

Simulate the model.

out = sim(simIn);

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 = setElement(ds,1,timeseries(5*ones(size(t)),t));
ds = setElement(ds,2,timeseries(10*sin(t),t));
ds = setElement(ds,3,timeseries(-5*ones(size(t)),t));

Create a Simulink.SimulationInput object and set the external inputs.

simIn = Simulink.SimulationInput('sldemo_mdlref_counter');
simIn = setExternalInput(simIn,ds);

Simulate the model.

out = parsim(simIn);

Version History

Introduced in R2017a