Main Content

set_param

Set Simulink parameter value

Description

example

set_param(object,parameter1,value1,...,parameterN,valueN) sets the specified Simulink® parameter parameter to the specified value value for the target object specified by object. The target object can be a model, subsystem, library, block, line, port, or bus element port element.

To set multiple parameter values for the target object, call the set_param function once with multiple name-value arguments instead of separately calling the function for each parameter. Setting multiple parameters with one function call is efficient because one call evaluates the parameters only once. If any parameter names or values are invalid, then the function does not set any parameters.

Examples

collapse all

Open the vdp model and set the Solver and StopTime parameter values.

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

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

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

Open vdp and set the Gain parameter value of the Gain block named Mu.

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

Open vdp and set the position of the Gain block named Mu.

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

Set the position of the Gain block named Mu in the vdp model using the block handle.

To get a handle to the Gain block named Mu, use the getSimulinkBlockHandle function. To load the vdp model, specify true.

mublockhandle = getSimulinkBlockHandle('vdp/Mu',true);

If you make multiple calls to set_param for the same block, use the block handle, which is more efficient than the full block path.

You can use the block handle in subsequent calls to get_param or set_param. The handle contains a double. Do not try to manually enter the number of a handle, for example 5.007, because you usually need to specify more digits than MATLAB® displays. Instead, assign the handle to a variable and use that variable name to specify the block.

Use the block handle with set_param to set the position.

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

Open vdp and, for the Gain block named Mu, set the block name on top of the block.

vdp
set_param('vdp/Mu','NameLocation','top')

Input Arguments

collapse all

Name, path, or handle of object, specified as a character vector, string scalar, or numeric scalar.

How you specify the target object depends on its type.

  • Model — Model name or handle.

  • Subsystem — Subsystem name or handle.

  • Library — Library name or handle.

  • Block — Block path or handle.

  • Line — Line handle.

  • Port — Port handle.

  • Bus element port element — Block path of model component with element label. The element can be any element of the port, such as a top-level bus, nested bus, signal, or message.

Example: 'vdp/Mu'

Example: 'mymodel/Subsystem1/Out1.nonsinusoidal.saw'

Tips

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

  • Do not try to manually specify the number of a handle, for example, 5.007, because you usually need to specify more digits than MATLAB displays. Assign the handle to a variable and use that variable name.

Data Types: char | string | double

Parameter, property, or attribute name, specified as a character vector or string scalar. Some names are case sensitive.

For information about parameters, properties, or attributes, see the programmatic use information on the corresponding reference pages. For example:

To get all parameters of a target object, use the get_param function with the 'ObjectParameters' option. Some of the returned parameters may be for internal use only.

Example: 'Solver'

Example: 'SimulationCommand'

Example: 'Position'

Example: 'NameLocation'

Data Types: char | string

Parameter value, specified in the format determined by the parameter type. Some parameter values are case sensitive. Values are often character vectors or string scalars, but they can also be numeric scalars, arrays, and other types.

Many block parameter values are specified as character vectors or string scalars. Two exceptions are Position, which is specified as a vector, and UserData, which can be any data type.

Limitations

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

Tips

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

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

Version History

Introduced before R2006a