setparam

Change value of tunable parameter in real-time application

Description

example

setparam(target_object, block_path, parameter_name, parameter_value) sets the value of a tunable block parameter to a new value. Specify the block parameter by the block name and the parameter name.

example

setparam(target_object, '', parameter_name, parameter_value) sets the value of the tunable global parameter to a new value. Specify the global parameter by the MATLAB® variable name.

Examples

collapse all

Set the value of the block parameter 'Amplitude' of the block 'Signal Generator' to 5.

tg = slrealtime('TargetPC1');
slbuild('slrt_ex_testmodel');
load(tg,'slrt_ex_testmodel');
setparam(tg,'slrt_ex_testmodel/Signal Generator','Amplitude',5)

Sweep the value of the block parameter 'Amplitude' of the block 'Signal Generator' by steps of 2.

tg = slrealtime('TargetPC1');
slbuild('slrt_ex_testmodel');
load(tg,'slrt_ex_testmodel');
for i = 1 : 3
    setparam(tg,'slrt_ex_testmodel/Signal Generator','Amplitude',(i*2))
end

Set the value of the MATLAB variable 'Freq' to 30.

tg = slrealtime('TargetPC1');
slbuild('slrt_ex_testmodel');
load(tg,'slrt_ex_testmodel');
setparam(tg,'','Freq',30)

Set the value of the MATLAB variable 'oscp.G2' to 10000000.

tg = slrealtime('TargetPC1');
slbuild('slrt_ex_testmodel');
load(tg,'slrt_ex_testmodel');
setparam(tg,'','oscp.G2',10000000)

Input Arguments

collapse all

Provides access to methods that manipulate the target computer properties.

Example: tg

The block_path values can be:

  • Empty character vector ('') or empty string scalar ("") for base or model workspace variables

  • Character vector or string scalar string for block path to parameters in the top model

  • Cell array of character vectors or string scalars for model block arguments

Example: '', 'Gain1', {'top/model','sub/model'}

The parameter can designate either a block parameter or a global parameter that provides the value for a block parameter. The block parameter or MATLAB variable must be observable to be accessible through the parameter name.

Note

Simulink® Real-Time™ does not support parameters of multiword data types.

Example: 'Gain', 'oscp.G1', 'oscp', 'G2'

New value with data type as required by parameter.

Example: 1

Introduced in R2020b