Simulink.SimulationInput - Create Simulink.SimulationInput objects to make changes to
model for multiple or individual simulations - MATLAB ([original](https://www.mathworks.com/help/simulink/slref/simulink.simulationinput.html)) ([raw](?raw))
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 thesetPreSimFcn
function and the setPostSimFcn
.
Creation
Syntax
Description
`simIn` = Simulink.SimulationInput([mdlName](#mw%5Fab33dddb-eaae-4fdc-b042-3ff9ec6c300b))
creates a Simulink.SimulationInput
object to configure a simulation of the model specified by mdlName
.
Input Arguments
Model name, specified as a string or a character vector. When you specify the model name, do not include the .slx
extension.
Properties
Name of the model for which the SimulationInput
object is created.
Initial state of the model for a simulation, specified as aSimulink.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
applyToModel | Apply configuration in SimulationInput object to model |
---|---|
getVariantConfiguration | Get name of variant configuration from SimulationInput object |
loadVariablesFromExternalSource | Load variables from a custom file into Simulink.SimulationInput object |
loadVariablesFromMATFile | Load variables from MAT file into Simulink.SimulationInput object |
removeVariable | Remove variable from SimulationInput orSimulation object |
setBlockParameter | Set block parameter values for simulation usingSimulationInput or Simulation object |
setExternalInput | Specify external input data for top-level input ports usingSimulationInput or Simulation object |
setInitialState | Specify initial state for simulation usingSimulationInput or Simulation object |
setPostSimFcn | Set MATLAB function to run after each simulation |
setPreSimFcn | Specify MATLAB function to run before start of each simulation onSimulink.SimulationInput object |
setModelParameter | Set model parameter values for simulation usingSimulationInput or Simulation object |
setVariable | Set variable values for simulation usingSimulationInput or Simulation object |
setVariantConfiguration | Set variant configuration for simulation using SimulationInput object |
showContents | View summary of specification in SimulationInput orSimulation object |
validate | Validate contents of SimulationInput object |
Examples
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 aSimulink.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 namedSet 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.
This example shows how use Dataset
objects to set external inputs with Simulink.SimulationInput
objects.
Open the model.
openExample("simulink_features/ComponentBasedModelingUsingModelReferenceExample") openProject("ModelReference"); 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(5ones(size(t)),t)); ds = setElement(ds,2,timeseries(10sin(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.
Version History
Introduced in R2017a
For variant models, use the VariantConfiguration
property to specify the variant configuration to apply to the model before the simulation runs. To set the property value, use the setVariantConfiguration
function.