Main Content

Simulink.SimulationInput class

Package:万博1manbetx
Superclasses:

CreatesSimulationInputobjects to make changes to a model for multiple or individual simulations

Description

TheSimulink.SimulationInputobject allows you to make changes to a model and run simulations with those changes. These changes are temporarily applied to the model. ThroughSimulink.SimulationInputobject, you can change:

  • Initial state

  • Model parameters

  • Block parameters

  • External inputs

  • Variables

Through theSimulink.SimulationInputobject, you can also specify MATLAB®functions to run at the start and the end of each simulation by usingin.setPreSimFcnandin.setPostSimFcn, respectively.

Construction

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

Input Arguments

expand all

Create aSimulink.SimulationInputobject by passing the name of the model as an argument.

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

Properties

expand all

Name of the model for which theSimulationInputobject is created.

Initial state of the model for a simulation specified as aSimulink.op.ModelOperatingPointobject.

External inputs added to the model for a simulation.

Block parameters 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 throughSimulationInputobject.

setBlockParameter

Set block parameters to be used for a specific simulation throughSimulationInputobject.

setInitialState

Set initial state to be used for a specific simulation throughSimulationInputobject.

setExternalInput

Set external inputs for a simulation throughSimulationInputobject.

setVariable

Set variables for a simulation throughSimulationInputobject.

setPreSimFcn

Specify a MATLAB function to run before start of each simulation throughSimulationInputobject.

setPostSimFcn

Specify a MATLAB function to run after each simulation is complete throughSimulationInputobject.

applyToModel

Apply changes to the model specified through aSimulationInputobject.

validate

Validate the contents of theSimulationInputobject.

loadVariablesFromMATFile

Load variables from MAT-file into aSimulink.SimulationInputobject.

Examples

collapse all

This example shows you how to create aSimulationInputobject.

Open the model.

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

Create a singleSimulationInputobject for a model.

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

This example shows you how to create an array ofSimulationInputobjects.

Create an array ofSimulationInputobjects by using theforloop.

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

This example modifies the block parameters of a model through theSimulationInputobject.

Open the model.

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

Create aSimulationInputobject for this model.

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

Modify block parameter.

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

Simulate the model.

out = sim(in)

This example shows how useDatasetobjects to set external inputs withSimulink.SimulationInputobjects.

Open the model

mdl ='sldemo_mdlref_counter'; open_system(mdl);

Create aDatasetobject 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 aSimulink.SimulationInputobject 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 theSimulationInputobject.

Simulate the model.

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

Simulate the model

out = parsim(in)

Version History

Introduced in R2017a