Setting up a notifier and listener in two different apps
3 ビュー (過去 30 日間)
古いコメントを表示
% 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
0 件のコメント
採用された回答
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 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!