필터 지우기
필터 지우기

Setting up a notifier and listener in two different apps

조회 수: 3 (최근 30일)
Scorp
Scorp 2022년 10월 24일
댓글: Scorp 2022년 10월 25일
% I have a mainApp built in AppDesigner. It calls another app that displays data from main app in a number of different plots. I would like the
% user to click on one of these plots, in this case UIAxes and the coordinates are sent back to the mainApp. How do I setup a listener in the
% mainApp for a notifier that is fired in the display app? I have tried the setup below, but once the startupFcn is finished the instance of the
% listener is destroyed.
classdef mainApp
events
dataFromDisplayApp
end
methods (Access=private)
function startupFcn(app)
listener(app, 'dataFromDisplayApp', @doSomethingAsResultOfDataFromDisplayApp
end
function doSomethingAsResultOfDataFromDisplayApp (app)
disp('Done something')
end
function userWantsAPlotButtonPushed(app, event)
displayApp(mainApp)
end
classdef displayApp
methods (Access=private)
function startupFcn (app, caller)
app.myMainApp = caller;
end
function UIAxesButtonDown(app, event)
notify(app.mainApp, 'dataFromDisplayApp')
end

채택된 답변

chrisw23
chrisw23 2022년 10월 24일
The "displayApp" has to provide the 'dataFromDisplay' event and the mainApp can add the listener.
app.myDisplayApp = displayApp(mainApp); % create the app object
app.liDispApp = addlistener(app.myDisplayApp,"dataFromDisplayApp",@app.dataFromDisplayApp_Callback); % register event

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Software Development Tools에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by