setBlockParameter - Set block parameter values for simulation using
SimulationInput or Simulation
object - MATLAB ([original](https://www.mathworks.com/help/simulink/slref/simulink.simulationinput.setblockparameter.html)) ([raw](?raw))
Set block parameter values for simulation usingSimulationInput
or Simulation
object
Syntax
Description
[s](#mw%5Fe7bee5c2-3826-4a61-a41b-97081a23acaf) = setBlockParameter([s](#mw%5Fe7bee5c2-3826-4a61-a41b-97081a23acaf),[blkpath](#bvqkv10-BlockPath),[blkparam](#bvqkv10-ParameterName),[paramval](#mw%5F2eeb4751-fe33-44d5-a7ec-9411520b34fc))
specifies the value of the block parameter blkparam
asparamval
for block blkpath
on theSimulink.SimulationInput or Simulation object s
.
- When
s
is aSimulationInput
object, you can specify only a single value to use for the entire simulation. - When
s
is aSimulation
object, you can specify a single value to use at the start of the simulation and specify new values for tunable parameters during normal and accelerator simulations.
Tuning block parameter values during rapid accelerator simulations is not supported.
You can use the setBlockParameter
function to specify parameter values on a SimulationInput
orSimulation
object for any block throughout a model hierarchy. The parameter values you specify override the values saved in the model for simulations you run using the SimulationInput
orSimulation
object during simulation and are reverted when the simulation completes. You can use a SimulationInput
orSimulation
object to override any number of parameter values.
Note
The setBlockParameter
function is not supported for rapid accelerator simulations that disable the rapid accelerator up-to-date check or for deployment. To modify block parameter values in these simulations, use a variable to specify the block parameter value, and then use the setVariable function to specify the variable value.
Examples
Modify a block parameter for a simulation using aSimulink.SimulationInput
object.
Open the model
mdl = "sldemo_househeat"; openExample("simulink_general/sldemo_househeatExample",... SupportingFile=mdl)
Create a SimulationInput
object for this model.
simin = Simulink.SimulationInput(mdl);
Modify block parameter value.
simin = setBlockParameter(simin,"sldemo_househeat/Set Point",... Value="300");
Simulate the model.
Modify multiple block parameter values for a simulation using a Simulink.SimulationInput
object.
Open the model
mdl = "vdp"; openExample("simulink_general/VanDerPolOscillatorExample",... SupportingFile=mdl)
Create a SimulationInput
object for this model.
simin = Simulink.SimulationInput(mdl);
Modify the Gain
parameter value for the Mu block and the position of the Product block.
simin = setBlockParameter(simin,"vdp/Mu","Gain","0.5",... "vdp/Product","Position",[50 100 110 120]);
Simulate the model.
Input Arguments
Simulation specification or simulation in which to set block parameter, specified as a Simulink.SimulationInput object or a Simulation object.
A SimulationInput
object represents a simulation specification that includes the initial state, external inputs, model parameter values, block parameter values, and variable values to use in the simulation. When you specify the first input argument as aSimulationInput
object:
- For each block parameter, you can specify only a single value to use for the entire simulation.
- You must specify the
SimulationInput
object as a return argument.
The Simulation
object represents a simulation and provides an interface for controlling and interacting with the simulation. When you specify the first input argument as a Simulation
object:
- For each block parameter, you can specify the initial value to use in the simulation.
- You can modify the values of tunable block parameters during normal and accelerator mode simulations.
- Specifying the
Simulation
object as a return argument is optional.
Example: simin = setBlockParameter(simin,"vdp/Mu","Gain","0.1")
specifies theGain parameter value for the block namedMu
in the model named vdp
as0.1
in the simulation configuration stored on theSimulationInput
objectsimin
.
Example: sm = setBlockParameter(sm,"vdp/Mu","Gain","0.1")
specifies theGain parameter value for the block namedMu
in the model named vdp
as0.1
in the simulation represented by theSimulation
object sm
.
Path to block for which to specify parameter value, specified as a string or a character vector.
Example: simin = setBlockParameter(simin,"vdp/Mu","Gain","0.1")
specifies theGain parameter value for the block namedMu
in the model named vdp
as0.1
in the simulation configuration stored on theSimulationInput
objectsimin
.
Example: sm = setBlockParameter(sm,"vdp/Mu","Gain","0.1")
specifies theGain parameter value for the block namedMu
in the model named vdp
as0.1
in the simulation represented by theSimulation
object sm
.
Name of block parameter to set, specified as a string or a character vector.
Example: simin = setBlockParameter(simin,"vdp/Mu","Gain","0.1")
specifies theGain parameter value for the block namedMu
in the model named vdp
as0.1
in the simulation configuration stored on theSimulationInput
objectsimin
.
Example: sm = setBlockParameter(sm,"vdp/Mu","Gain","0.1")
specifies theGain parameter value for the block namedMu
in the model named vdp
as0.1
in the simulation represented by theSimulation
object sm
.
Block parameter value, specified as a valid value for the specified block parameter. Many block parameters, such as the Gain parameter of the Gain block, require specifying the parameter value as a string or a character vector, including for numeric block parameter values.
Example: simin = setBlockParameter(simin,"vdp/Mu","Gain","0.1")
specifies theGain parameter value for the block namedMu
in the model named vdp
as0.1
in the simulation configuration stored on theSimulationInput
objectsimin
.
Example: sm = setBlockParameter(sm,"vdp/Mu","Gain","0.1")
specifies theGain parameter value for the block namedMu
in the model named vdp
as0.1
in the simulation represented by theSimulation
object sm
.
Output Arguments
Simulation specification or simulation with block parameter added or modified, returned as a Simulink.SimulationInput object or a Simulation object.
When you use the setBlockParameter
function to specify the value of a block parameter on a SimulationInput
object, you must specify the SimulationInput
object as the return argument.
When you use the setModelParameter
function to specify the value of a block parameter on a Simulation
object, assigning the return argument is optional.
Tips
- Use the
getBlockParameter
function to get the value of a block parameter specified on aSimulationInput
object or aSimulation
object.
paramval = getBlockParameter(s,blkpath,"ParamName"); - Use the
removeBlockParameter
function to remove a block parameter from aSimulationInput
object or aSimulation
object.
s = removeBlockParameter(s,blkpath,"ParamName");
Version History
Introduced in R2017a
The Simulation
object represents a simulation and provides an interface to control simulation execution and tune model parameter, block parameter, and variable values during simulation. You can use the setBlockParameter
, getBlockParameter
, and removeBlockParameter
functions to configure block parameter values for a single simulation and tune variable values during simulation.