setparam

Change value of tunable parameter in real-time application

Description

example

setparam(target_object, parameter_block_name, parameter_name, parameter_value) sets the value of a tunable block parameter to a new value. Specify the block parameter by block name and 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 MATLAB® variable name.

example

setparam(target_object, parameter_index, parameter_value) sets the value of the tunable block or global parameter to a new value. Specify the parameter by parameter index.

example

setparam(target_object, parameter_index_vec, param_value_cell_array) sets the value of the tunable block or global parameter to a new value. Specify the parameter by a vector of parameter indexes and the new value as a cell array.

example

history_struct = setparam(target_object, ___) sets the value of the tunable block or global parameter to a new value as specified by the parameters. This method returns a structure that stores the parameter specification, previous parameter values, and new parameter values.

Examples

collapse all

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

tg = slrt;
setparam(tg, 'Signal Generator', 'Amplitude', 5)

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

tg = slrt;
for i = 1 : 3
    setparam(tg, 'Signal Generator', 'Amplitude', (i*2))
end

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

tg = slrt;
setparam(tg, 'Freq', 30)

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

tg = slrt;
setparam(tg, 'oscp.G2',10000000)

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

tg = slrt;
history_struct = setparam(tg, 'Signal Generator', 'Amplitude', 5)
history_struct = 

       Source: {'Signal Generator'  'Amplitude'}
    OldValues: 4
    NewValues: 5

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

tg = slrt;
history_struct = setparam(tg, 'Freq', 30)
history_struct = 

       Source: {'Freq'}
    OldValues: 20
    NewValues: 30

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

tg = slrt;
history_struct = setparam(tg, 'oscp.G2',10000000)
history_struct = 

       Source: {'oscp'}
    OldValues: [1x1 struct]
    NewValues: 10000000

Get the signal index of block parameter 'Gain' of block 'Gain1', and then set the parameter value to 10000000.

tg = slrt;
pid = getparamid(tg, 'Gain1', 'Gain');
setparam(tg, pid, 10000000)

Get the signal index of MATLAB variable 'G2', and then set the parameter value to 10000000.

tg = slrt;
pid = getparamid(tg, '', 'G2');
setparam(tg, pid,10000000)

Get the signal indexes of block parameters 'Gain' of blocks 'Gain1' and 'Gain2', and then set the parameter values to 10000000 and 400 respectively.

tg = slrt;
pid1 = getparamid(tg, 'Gain1', 'Gain');
pid2 = getparamid(tg, 'Gain2', 'Gain');
setparam(tg, [pid1, pid2], {10000000, 400})

Input Arguments

collapse all

Object that represents the target computer. Before calling this function, make sure that you start the target computer with the Simulink® Real-Time™ kernel and apply the required Ethernet link settings.

Example: tg

The empty character vector ('') or empty string scalar ("") as a block name marks a global parameter that provides the value for a block parameter. The MATLAB variable is not associated with a particular block.

Example: 'Gain1', ''

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

Note

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

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

The parameter index can mark either a block parameter or a global parameter that provides the value for a block parameter. To be accessible via parameter index, the block parameter or MATLAB variable must be observable.

To access a parameter index, type tg.ShowParameters = 'on' in the Command Window, and count lines starting with 0.

Note

Parameter access by parameter index will be removed in a future release. Access parameters by parameter name instead.

Example: 0, 1

New value with data type as required by parameter.

Example: 1

Parameter indexes returned by getparamid

Example: [1,2,3]

New values with data types as required by parameter. The cell array must contain the same number of values as the parameter index vector.

Example: {1,2,3}

Output Arguments

collapse all

Structure containing the following fields:

  • Source — Reference to parameters being changed, in the same format as the input argument or arguments. If the input arguments are name character vectors or string scalars, Source contains name character vectors. If the input argument is a parameter index or vector of parameter indexes, Source contains a parameter index or a vector of parameter indexes.

  • OldValues — Values held by parameter or parameters before change.

  • NewValues — Values held by parameter or parameters before change.

Example:

Source: {'Signal Generator' 'Amplitude'}
OldValues: 4
NewValues: 5

Data Types: struct

Introduced in R2014a