Documentation

set_param

Set system and block parameter values

Syntax

  • set_param(Object,ParameterName,Value,...ParameterNameN,ValueN) example

Description

example

set_param(Object,ParameterName,Value,...ParameterNameN,ValueN) sets the parameter to the specified value on the specified model or block object.

When you set multiple parameters on the same model or block, use a single set_param command with multiple pairs of ParameterName, Value arguments, rather than multiple set_param commands. This technique is efficient because using a single call requires evaluating parameters only once. If any parameter names or values are invalid, then the function doesn't set any parameters.

Tips:

  • If you make multiple calls to set_param for the same block, then specifying the block using a numeric handle is more efficient than using the full block path. Use getSimulinkBlockHandle to get a block handle.

  • If you use matlab -nodisplay to start a session, you cannot use set_param to run your simulation. The -nodisplay mode does not support simulation using set_param. Use the sim command instead.

  • After you set parameters in the MATLAB® workspace, to see the changes in a model, update the diagram.

    set_param(model,'SimulationCommand','Update')

For parameter names, see:

Examples

collapse all

Set Model Configuration Parameters for a Model

Open vdp and set the Solver and StopTime parameters.

vdp
set_param('vdp','Solver','ode15s','StopTime','3000')

Set Model Configuration Parameters for Current Model

Open a model and set the Solver and StopTime parameters. Use bdroot to get the current top-level model.

vdp
set_param(bdroot,'Solver','ode15s','StopTime','3000')

Set a Gain Block Parameter Value

Open vdp and set a Gain parameter value in the Mu block.

vdp
set_param(‘vdp/Mu','Gain','10')

Set Position of Block

Open vdp and set the position of the Fcn block.

vdp
set_param('vdp/Fcn','Position',[50 100 110 120])

Set Position of Block Using a Handle

Set the position of the Fcn block in the vdp model.

Use getSimulinkBlockHandle to load the vdp model if necessary (by specifying true), and get a handle to the Fcn block. If you make multiple calls to set_param for the same block, then using the block handle is more efficient than specifying the full block path as a string.

fcnblockhandle = getSimulinkBlockHandle('vdp/Fcn',true);

You can use the block handle in subsequent calls to get_param or set_param. If you examine the handle, you can see that it contains a double. Do not try to use the number of a handle alone (e.g., 5.007) because you usually need to specify many more digits than MATLAB displays. Instead, assign the handle to a variable and use that variable name to specify a block.

Use the block handle with set_param to set the position.

set_param(fcnblockhandle,'Position',[50 100 110 120])

Related Examples

Input Arguments

collapse all

Object — Name or handle of a model or blockstring | handle

Handle or name of a model or block, specified as a numeric handle or a string. A numeric handle must be a scalar. You can also set parameters of lines and ports, but you must use numeric handles to specify them.

    Tip   If you make multiple calls to set_param for the same block, then specifying a block using a numeric handle is more efficient than using the full block path with set_param. Use getSimulinkBlockHandle to get a block handle. Do not try to use the number of a handle alone (e.g., 5.007) because you usually need to specify many more digits than MATLAB displays. Assign the handle to a variable and use that variable name to specify a block.

Example: 'vdp/Fcn'

ParameterName — Model or block parameter namestring

Model or block parameter name, specified as the comma-separated pair consisting of the parameter name, specified as a string, and the value, specified in the format determined by the parameter type. Case is ignored for parameter names. Value strings are case sensitive. Values are often strings, but they can also be numeric, arrays, and other types. Many block parameter values are specified as strings, but two exceptions are these parameters: Position, specified as a vector, and UserData, which can be any data type.

Example: 'Solver','ode15s','StopTime','3000'

Example: 'SimulationCommand', 'start'

Example: 'Position',[50 100 110 120]

Data Types: char

Was this topic helpful?