Main Content

setBlockParameter

Set block parameter values for simulation using SimulationInput or Simulation object

Description

s = setBlockParameter(s,blkpath,blkparam,paramval) specifies the value of the block parameter blkparam as paramval for block blkpath on the Simulink.SimulationInput or Simulation object s.

  • When s is a SimulationInput object, you can specify only a single value to use for the entire simulation.

  • When s is a Simulation 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 or Simulation 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 or Simulation object during simulation and are reverted when the simulation completes. You can use a SimulationInput or Simulation 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.

example

Examples

collapse all

Modify a block parameter for a simulation using a Simulink.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.

out = sim(simin);

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.

out = sim(simin);

Input Arguments

collapse all

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 a SimulationInput 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 the Gain parameter value for the block named Mu in the model named vdp as 0.1 in the simulation configuration stored on the SimulationInput object simin.

Example: sm = setBlockParameter(sm,"vdp/Mu","Gain","0.1") specifies the Gain parameter value for the block named Mu in the model named vdp as 0.1 in the simulation represented by the Simulation 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 the Gain parameter value for the block named Mu in the model named vdp as 0.1 in the simulation configuration stored on the SimulationInput object simin.

Example: sm = setBlockParameter(sm,"vdp/Mu","Gain","0.1") specifies the Gain parameter value for the block named Mu in the model named vdp as 0.1 in the simulation represented by the Simulation 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 the Gain parameter value for the block named Mu in the model named vdp as 0.1 in the simulation configuration stored on the SimulationInput object simin.

Example: sm = setBlockParameter(sm,"vdp/Mu","Gain","0.1") specifies the Gain parameter value for the block named Mu in the model named vdp as 0.1 in the simulation represented by the Simulation 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 the Gain parameter value for the block named Mu in the model named vdp as 0.1 in the simulation configuration stored on the SimulationInput object simin.

Example: sm = setBlockParameter(sm,"vdp/Mu","Gain","0.1") specifies the Gain parameter value for the block named Mu in the model named vdp as 0.1 in the simulation represented by the Simulation object sm.

Output Arguments

collapse all

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 a SimulationInput object or a Simulation object.

    paramval = getBlockParameter(s,blkpath,"ParamName");

  • Use the removeBlockParameter function to remove a block parameter from a SimulationInput object or a Simulation object.

    s = removeBlockParameter(s,blkpath,"ParamName");

Version History

Introduced in R2017a

expand all