How to use App Designer helper functions as Simulink callback methods.

V
Vankadari · Sep 7, 2021 · 2.3K views
Question
I am running a simulink model from app designer which plots the simulink output. For this I'm using Event Listener method approach.   The code I used in Simulink 'StartFcn' is :   blk2 = 'SineWave/Scope'; event = 'PostOutputs'; listener = @updateAxes; % Create the listener h1 = add_exec_event_listener(blk2, event, listener); Here the updateAxes is an .m script that updates the App Designer axes. This runs without errors as a separate script.   But, I want to create a helper function in my app and use it as the above listener 'updateAxes' function. is it possible?
Expert Answer
Profile picture of John Michell
John Michell PhD Expert
Answered Aug 30, 2026
"Simulink software can register a listener only while a simulation is running. Invoking this function when no simulation is running results in an error message. To ensure that a listener catches all relevant events triggered by a model's simulation, you should register the listener in the model's StartFcn callback function (see Callbacks for Customized Model Behavior)."
That tells us that you cannot directly register the listener from within App Designer.
And that means in turn that the challenge is that when you do the @updateAxes equivalent, that the function you register must be visible inside the StartFcn.
 
It appears to me that app designer subclasses from handle. In theory if you had a small function or script that invoked the class, you could write the handle into the base workspace, where in theory it should be accessible to Simulink. Or if you do not want to use a small wrapper, then in theory you could have your App assignin('base') to assign a variable that is directly a handle to the function you want to invoke, like
 
 
blk2 = 'SineWave/Scope';
event = 'PostOutputs';
listener = Listener_Handle_Stored_by_App;
% Create the listener
h1 = add_exec_event_listener(blk2, event, listener);
100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!