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.

Since R2024a

Name of variant configuration to apply to the model before running the simulation, specified as a string or character vector.

This property is applicable for models that use variant elements such as variant blocks and variant parameters, and also have variant configurations created for the model using Variant Manager for Simulink®. For such a model, you can specify a variant configuration that can activate a specific variant path across the model hierarchy before the simulation runs.

For an example, see Run Simulations for Variant Models Using Variant Configurations.

Example: "LinInterExpNoNoise"

Data Types: char | string

Object Functions

applyToModelApply configuration in SimulationIntput object to model
getVariantConfigurationGet name of variant configuration from SimulationInput object
loadVariablesFromExternalSourceLoad variables from a custom file into Simulink.SimulationInput object
loadVariablesFromMATFileLoad variables from MAT file into Simulink.SimulationInput object
removeVariableRemove variable from SimulationInput or Simulation object
setBlockParameterSet block parameter values for simulation using SimulationInput or Simulation object
setExternalInputSpecify external input data for top-level input ports using SimulationInput or Simulation object
setInitialStateSpecify initial state for simulation using SimulationInput or Simulation object
setPostSimFcn Set MATLAB function to run after each simulation
setPreSimFcnSpecify MATLAB function to run before start of each simulation on Simulink.SimulationInput object
setModelParameterSet model parameter values for simulation using SimulationInput or Simulation object
setVariableSet variable values for simulation using SimulationInput or Simulation object
setVariantConfigurationSet variant configuration for simulation using SimulationInput object
showContentsView summary of specification in SimulationInput or Simulation 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('ex_sldemo_househeat/Set Point', ...
	'Value',num2str(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

expand all