Main Content

set_param

Set system and block parameter values

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 singleset_paramcommand with multiple pairs ofParameterName,Valuearguments, rather than multipleset_paramcommands. 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 toset_paramfor the same block, then specifying the block using a numeric handle is more efficient than using the full block path. UsegetSimulinkBlockHandleto get a block handle.

  • If you usematlab -nodisplayto start a session, you cannot useset_paramto run your simulation. The-nodisplaymode does not support simulation usingset_param. Use thesimcommand 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

Openvdpand set theSolverandStopTimeparameters.

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

Open a model and set theSolverandStopTimeparameters. Usebdrootto get the current top-level model.

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

Openvdpand set aGainparameter value in theMublock.

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

Openvdpand set the position of theMublock.

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

Set the position of theMublock in thevdpmodel.

UsegetSimulinkBlockHandleto load thevdpmodel if necessary (by specifyingtrue), and get a handle to theMublock. If you make multiple calls toset_paramfor the same block, then using the block handle is more efficient than specifying the full block path as a character vector.

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

You can use the block handle in subsequent calls toget_paramorset_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 withset_paramto set the position.

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

Set the position of the Mu block name on top in thevdpmodel.

Open thevdpmodel. Typevdpat the command line.

Select the Mu block.

组块的名字在上面。

set_param(gcb,'NameLocation','top')

Input Arguments

collapse all

Handle or name of a model or block, specified as a numeric handle or a character vector. 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 toset_paramfor the same block, then specifying a block using a numeric handle is more efficient than using the full block path withset_param. UsegetSimulinkBlockHandleto 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/Mu'

Model or block parameter name, specified as a character vector or a string scalar. Some parameter names are case sensitive.

Example:'Solver'

Example:'SimulationCommand'

Example:'Position'

Example:'NameLocation'

Model or block parameter value, specified in the format determined by the parameter type. Some parameter values are case sensitive. Values are often character vectors, but they can also be numeric, arrays, and other types. Many block parameter values are specified as character vectors, but two exceptions are these parameters:Position, specified as a vector, andUserData, which can be any data type.

Example:'right''left''top''bottom'

Introduced before R2006a