Main Content

getparam

Read value of observable parameter in real-time application

Description

example

value = getparam(target_object, block_path, parameter_name) returns the value of block parameter parameter_name in block block_path from the real-time application that is loaded on the target computer.

example

value = getparam(target_object, '', parameter_name) returns the value of global parameter parameter_name.

Examples

collapse all

This example builds a real-time application from model slrt_ex_testmodel, loads the application on the target computer, and gets the value of block parameter 'Amplitude' of block 'Signal Generator'.

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

     4

This example assumes that in model slrt_ex_testmodel you previously created a variable Freq and assigned the Frequency parameter value to Freq. The example builds a real-time application from model slrt_ex_testmodel, loads the application on the target computer, and gets the value of MATLAB® variable 'Freq'.

tg = slrealtime('TargetPC1');
slbuild('slrt_ex_testmodel');
load(tg, 'slrt_ex_testmodel');
getparam(tg,'','Freq')
ans =

     20

This example creates an array of gain values and assigns the gain parameters to its elements. The example builds a real-time application from model slrt_ex_testmodel, loads the application on the target computer, and gets the value of parameter structure 'oscp'.

oscp.G0 = 1000000;
oscp.G1 = 400;
oscp.G2 = 1000000;
set_param('slrt_ex_testmodel/Gain','Gain','oscp.G0');
set_param('slrt_ex_testmodel/Gain1','Gain','oscp.G1');
set_param('slrt_ex_testmodel/Gain2','Gain','oscp.G2');
tg = slrealtime('TargetPC1');
slbuild('slrt_ex_testmodel');
load(tg,'slrt_ex_testmodel');
getparam(tg,'','oscp')
ans = 

    G0: 1000000
    G1: 400
    G2: 1000000

Get the value of the MATLAB variable 'spkp.g_gain' from the real-time application.

open_system('slrt_ex_osc_struct');
load('slrt_ex_osc_struct.mat');
tg = slrealtime('TargetPC1');
slbuild('slrt_ex_osc_struct');
load(tg,'slrt_ex_osc_struct');
getparam(tg,'','spkp.g_gain')
ans = 

    1000000

The getparam and setparam functions support dot notation syntax to access parameter values in real-time applications. These are examples of more advanced syntax.

% If a parameter is a struct, a single element of any 
% array can be specified at any arbitrary depth in the struct.
tg.setparam('', 'p.a.b(2).c', val) 
val = tg.getparam('', 'p.a.b(2).c') 

% If a parameter is an array of structs, one element of 
% the struct array can be specified as follows:
tg.setparam('', 'p(2,2).x.y.z', val) 
val = tg.getparam('', 'p(2,2).x.y.z') 

% If a parameter is N dimensions, a single element of 
% the parameter can be accessed by specifying each dimension.
tg.setparam('top/constant', 'Value(3,4)', val) 
val = tg.getparam('top/constant', 'Value(3,4)') 

% If a parameter is Mx1 or 1xN (row or column vector), 
% the following syntax specifying a single index 
% is allowed: 
tg.setparam('top/constant1', 'Value(4)', val)

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'

Output Arguments

collapse all

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

Introduced in R2020b