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

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

example

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.

mdl = "sldemo_househeat";
openExample("simulink_general/sldemo_househeatExample",...
    SupportingFile=mdl)

Create a single SimulationInput object for the model.

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.

mdl = "vdp";
openExample("simulink_general/VanDerPolOscillatorExample",...
    SupportingFile=mdl)

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

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.

mdl = "sldemo_househeat";
openExample("simulink_general/sldemo_househeatExample",...
    SupportingFile=mdl)

Create an array of SimulationInput object for the model.

simin(1:10) = Simulink.SimulationInput(mdl);

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

blk = mdl + "/Set Point";
for k = 1:10
simin(k) = setBlockParameter(simin(k),blk,...
	Value=num2str(rand()*10+70));
end

Simulate the model.

out = parsim(simin);

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

Open the model

mdl = "sldemo_mdlref_counter";
openExample(...
    "simulink/ExamineMultipleReferencedModelInstancesExample",...
    SupportingFile=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(mdl);
simin = setExternalInput(simin,ds);

Simulate the model.

out = sim(simin);

Version History

Introduced in R2017a

expand all