Main Content

Simulink.SimulationInput

Create Simulink.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, and 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.

Creation

Description

example

simIn = Simulink.SimulationInput(mdlName) creates a Simulink.SimulationInput object to configure a simulation of the model specified by mdlName.

Input Arguments

expand all

Model name, specified as a string or a character vector. When you specify the model name, do not include the .slx extension.

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.

Object Functions

applyToModelApply configuration specified on Simulink.SimulationIntput object to model
loadVariablesFromExternalSourceLoad variables from a custom file into Simulink.SimulationInput object
loadVariablesFromMATFileLoad variables from MAT file into Simulink.SimulationInput object
removeVariableRemove variable from Simulink.SimulationInput object
setBlockParameterSet block parameter values on Simulink.SimulationInput object
setExternalInputSpecify external input data for top-level input ports in simulation configured using Simulink.SimulationInput object
setInitialStateConfigure Simulink.SimulationInput object to set initial state for simulation
setPostSimFcn Set MATLAB function to run after each simulation
setPreSimFcnSpecify MATLAB function to run before start of each simulation on Simulink.SimulationInput object
setModelParameterSpecify parameter values for simulation configured using Simulink.SimulationInput object
setVariableSet variable value on SimulationInput object
showContentsView contents of Simulink.SimulationInput object
validateValidate contents of SimulationInput object

Examples

collapse all

Create a SimulationInput object to configure a simulation of the model sldemo_househeat.

Open the model.

openExample("simulink_general/sldemo_househeatExample") 

Create a single SimulationInput object for the model.

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

This example shows you how to create an array of SimulationInput objects to configure several simulations of the model vdp.

Open the model.

openExample("simulink_general/VanDerPolOscillator")

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

mdl = "vdp";
simIn(1:10) = Simulink.SimulationInput(mdl);

Modify the value of a block parameter for a simulation of the model sldemo_househeat using a Simulink.SimulationInput object.

Open the model.

openExample("sldemo_househeat")

Create an array of SimulationInput object for the model.

mdl = "sldemo_househeat";
simIn(1:10) = Simulink.SimulationInput(mdl);

Specify the Value parameter for the block named Set Point using the setBlockParameter function.

for i = 1:10
simIn(i) = simIn(i).setBlockParameter(simIn,'ex_sldemo_househeat/Set Point',
   'Value',rand()*10+70);
end

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