1.将使用的Simulink模型命名为“Trial.slx”,将使用的App Designer应用命名为“TrialApp.mlapp”。从App Designer访问Simulink模型的运行时参数涉及三个步骤。它们列在下面
1. In the Simulink model callback "InitFcn" function, define:
hApp = TrialApp;
2. In the Simulink model callback "StartFcn" function, call a function named "updateGUI()" as described below. This method will be called every time the specified block's ("blk") output method executes.
blk = 'Trial/DisplayBox';
event = 'PostOutputs';
listener = @(app, event) updateGUI(hApp);
h = add_exec_event_listener(blk, event, listener);
3.Create a public method named "updateGUI()" in the app designed in App Designer. This function will get the specified block's run-time parameters and pass it to the GUI. This function is defined below.3.在应用程序设计器中设计的应用程序中创建名为“updateGUI()”的公共方法。此函数将获取指定块的运行时参数并将其传递给GUI。此函数定义如下
function updateGUI(app, varargin)
% Create an object that gets the run-time value of the specified block
rto = get_param([bdroot,'/DisplayBox'],'RuntimeObject');
% Update the GUI accordingly. In this case a the value of an EditField is being updated.
app.EditField.Value = rto.InputPort(1).Data;
end
参考文献
matlab中get_param命令的使用方法_moxiangxiaozhu的博客-CSDN博客_get_param
命令:
open_system('vdp');
g = get_param('vdp/Mu','Gain');
v = str2double(g) + 1;
set_param('vdp/Mu','Gain',num2str(v));
close_system('vdp',0);
sim('vdp');
%%自己的话描述一下上述步骤
1.打开simulink模型,右键-model properties-callbacks-InitFcn
把simulink模型和app绑在一起:happ=TrialApp;happ就是这个名字不可更改
2.在StartFcn中,(1)把要输出参数的模块命名;(2)event='PostOutputs';(3)