getparam
Syntax
Description
returns the value of block parameter
value
= getparam(target_object
, block_path
, parameter_name
)parameter_name
in block
block_path
from the real-time application
that is loaded on the Speedgoat® target
computer.
returns the value of global parameter
value
= getparam(target_object
, '', parameter_name
)parameter_name
.
Examples
Get Block Parameter by Using Parameter and Block Names
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'); model = 'slrt_ex_osc'; xfername = [model,'/Signal Generator']; slbuild(model); load(tg,model); getparam(tg,xfername,'Amplitude')
ans = 1
Get Global Parameter by Using Scalar Parameter Name
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'); model = 'slrt_ex_osc'; openExample(model); Freq = Simulink.Parameter; Freq.StorageClass = 'ExportedGlobal'; Freq.Value = 10; xfername = [model,'/Signal Generator']; set_param(xfername,'Frequency','Freq'); slbuild(model); load(tg,model); getparam(tg,'','Freq')
ans = 10
Get Global Parameter by Using Parameter Structure Name
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'
.
tg = slrealtime('TargetPC1'); model = 'slrt_ex_osc_struct'; openExample(model); load('slrt_ex_osc_struct.mat'); slbuild(model); load(tg,model); getparam(tg,'','spkp')
ans = struct with fields: sg_freq: 20 g2_gain: 1000000 g1_gain: 400 g_gain: 1000000
Get Global Parameter by Parameter Structure Field Name
Get the value of the MATLAB variable 'spkp.g_gain'
from the real-time
application.
tg = slrealtime('TargetPC1'); model = 'slrt_ex_osc_struct'; openExample(model); load('slrt_ex_osc_struct.mat'); slbuild(model); load(tg,model); getparam(tg,'','spkp.g2_gain')
ans = 1000000
Access Parameter Values in Parameter Structure
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
target_object
— Object that represents target computer
slrealtime.Target
object
Provides access to methods that manipulate the target computer properties.
Example: tg
block_path
— Hierarchical name of the originating block
character vector | string scalar | cell array of character vectors or strings
The block_path
values can be:
Empty character vector (
''
) or empty string scalar (""
) for base or model workspace variablesCharacter vector or string scalar for block path to parameters in the top model
Cell array of character vectors or string scalars for model block arguments and model instance parameters
Example: ''
, 'Gain1'
,
{'top/model','sub/model'}
parameter_name
— Name of the parameter
character vector | string scalar
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
value
— Value of parameter
number | character vector | string scalar | complex | structure | numeric array
Simulink Real-Time does not support parameters of multiword data types.
Version History
Introduced in R2020bR2024a: Apply Initial Conditions at Application Start
R2021b: Parameter Structure for getparam and setparam
The operation of the getparam
function and
setparam
function supports dot notation for:
Specifying a field of a struct for
getparam
. It has the same support assetparam
.Specifying an element of a struct array or matrix for
getparam
andsetparam
.Specifying one field of a struct when any substructure is an array of structs for
getparam
andsetparam
.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)