Function related to Event Listener not found

1 view (last 30 days)
tahec
tahec on 28 Jun 2017
Edited: tahec on 29 Jun 2017
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.

Answers (1)

Walter Roberson
Walter Roberson on 29 Jun 2017
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 Comment
tahec
tahec on 29 Jun 2017
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.

Sign in to comment.

Categories

Find more on Event Functions in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!