主要内容

本页采用了机器翻译。点击此处可查看英文原文。

getparam

在实时应用中读取可观测参数的值

说明

value = getparam(target_object, block_path, parameter_name) 返回在 Speedgoat® 目标计算机上加载的实时应用程序中,block_path 模块内 parameter_name 模块参数的值。

示例

value = getparam(target_object, '', parameter_name) 返回全局参数 parameter_name 的值。

示例

示例

全部折叠

此示例基于模型 slrt_ex_testmodel 构建实时应用程序,将应用程序加载到目标计算机上,并获取模块 'Signal Generator' 中模块参数 'Amplitude' 的值。

tg = slrealtime('TargetPC1');
model = 'slrt_ex_osc';
xfername = [model,'/Signal Generator'];
slbuild(model);
load(tg,model);
getparam(tg,xfername,'Amplitude')
ans =

     1

此示例假设在模型 slrt_ex_testmodel 中,您已事先创建变量 Freq,并将参数值 Frequency 赋值给变量 Freq。该示例基于模型 slrt_ex_testmodel 构建实时应用程序,将应用程序加载到目标计算机上,并获取 MATLAB® 变量 '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

此示例创建一个增益值数组,并将增益参数分配给其元素。该示例基于模型 slrt_ex_testmodel 构建实时应用程序,在目标计算机上加载该应用程序,并获取参数结构 '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

从实时应用程序中获取 MATLAB 变量的值 'spkp.g_gain'

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

getparamsetparam 函数支持点表示法语法,用于在实时应用程序中访问参数值。这些是更高级语法的示例。

% 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)

输入参数

全部折叠

提供访问方法以操作目标计算机属性。

示例: tg

block_path 的取值可以是:

  • 空字符向量 ('') 或空字符串标量 ("") 用于基准或模型工作区变量

  • 字符向量或字符串标量,用于表示顶层模型中参数的块路径

  • 用于模型块参数和模型实例参数的字符向量或字符串标量元胞数组

示例: '', 'Gain1', {'top/model','sub/model'}

该参数可指定为模块参数,或指定为提供模块参数值的全局参数。模块参数或 MATLAB 变量必须可观察,才能通过参数名称访问。

注意

Simulink® Real-Time™ 不支持多词数据类型的参数。

示例: 'Gain', 'oscp.G1', 'oscp', 'G2'

输出参量

全部折叠

Simulink Real-Time 不支持多词数据类型的参数。

版本历史记录

在 R2020b 中推出

全部展开