How to use app designer's 'Helper Functions' outside the app, precisely in Simulink callbacks.

조회 수: 1 (최근 30일)
I am designing an app that plots the output of a simulink model. For this I am using Event Listener method. I acheived this by adding the event listener directly in the 'StartFcn' of the simulink model and creating a Script for updating the plot.
But I wanted to add the event listener using methods(functions) of the app(Task_1).
The reuired code for now, that I wrote in the buttonpushedcallback is:
set_param('Task1', 'SimulationMode','external');
set_param('Task1', 'StartFcn', 'Task_1.addEventListener'); % 2nd line
set_param('Task1', 'SimulationCommand','AccelBuild');
set_param('Task1', 'SimulationCommand','connect');
set_param('Task1', 'SimulationCommand', 'start');
Here in the 2nd line, I added the event listener which directs to the static methods that is declaredin the same app, as shown below:
methods (Static)
function addEventListener
Blk = 'Task1/Scope'; % Task1 is my simulink model.
Event = 'PostOutputs';
Listener = @Task_1.execEventListener;
EL = add_exec_event_listener(Blk, Event,Listener); % Break point1
end
function execEventListener()
disp('Exec Works') % Break Point2
% I just wrote this one line because this method isn't executing at all.
end
end
The problem I am facing here is, when the simulink model strats running, the 'StartFcn callback' executes and enters the addEventListener method(function) and stops at break point1. Now when I press continue, the 'execEventListener' is not executing i.e. the program is not stopping at break point 2 and running the simulink model.
Can someone guide me through this please.
OR
Please show me the right way to use a helper function from app designer to a simulink callback.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Target Computer Setup에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by