getparam
在实时应用中读取可观测参数的值
语法
说明
返回在 Speedgoat® 目标计算机上加载的实时应用程序中,value = getparam(target_object, block_path, parameter_name)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 =
1000000getparam 和 setparam 函数支持点表示法语法,用于在实时应用程序中访问参数值。这些是更高级语法的示例。
% 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)
输入参数
表示目标计算机的对象,指定为 Target 对象。该对象提供了用于操作目标计算机属性的方法。
示例: tg
block_path 的取值可以是:
空字符向量 (
'') 或空字符串标量 ("") 用于基准或模型工作区变量字符向量或字符串标量,用于表示顶层模型中参数的块路径
用于模型块参数和模型实例参数的字符向量或字符串标量元胞数组
示例: '', 'Gain1', {'top/model','sub/model'}
该参数可指定为模块参数,或指定为提供模块参数值的全局参数。模块参数或 MATLAB 变量必须可观察,才能通过参数名称访问。
注意
Simulink® Real-Time™ 不支持多词数据类型的参数。
示例: 'Gain', 'oscp.G1', 'oscp', 'G2'
输出参量
Simulink Real-Time 不支持多词数据类型的参数。
版本历史记录
在 R2020b 中推出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.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)