Function related to Event Listener not found

1 回表示 (過去 30 日間)
tahec
tahec 2017 年 6 月 28 日
編集済み: tahec 2017 年 6 月 29 日
Hi all,
I have a simulink model (.slx file) and a gui (.mlapp file created with App Designer). They are located into the same folder. I added the following code to the StartFcn of the simulink model
h = add_exec_event_listener('blockDiagram/mySubSys', 'PostOutputs', @gui.myFunc);
and I defined a function, called myFunc, into the gui file, in this way
methods (Access = public)
function myFunc(block, ~)
% code
end
end
Unfortunately, when I run the model, the Command Window displays the following error
Undefined function 'gui.myFunc' for input arguments of type 'Simulink.RunTimeBlock'.
So, how can I solve this problem ?
Thank you for reading.

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 6 月 29 日
Perhaps
h = add_exec_event_listener('blockDiagram/mySubSys', 'PostOutputs', @(varargin) gui.myFunc);
or
h = add_exec_event_listener('blockDiagram/mySubSys', 'PostOutputs', @(varargin) myFunc(gui));
  1 件のコメント
tahec
tahec 2017 年 6 月 29 日
Hi, thank you for your reply. When I use the first expression, MATLAB says me
The class gui has no Constant property or Static method named 'myFunc'.
Error in gui>@(varargin)gui.myFunc
When I use the second expression, MATLAB opens several windows of my GUI, but it doesn't print any error message.
However, App Designer suggests that I have to "use app as the first argument for myFunc". But the result is the same.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeEvent Functions についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by