Setting up a notifier and listener in two different apps

2 Ansichten (letzte 30 Tage)
Scorp
Scorp am 24 Okt. 2022
Kommentiert: Scorp am 25 Okt. 2022
% 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

Akzeptierte Antwort

chrisw23
chrisw23 am 24 Okt. 2022
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

Weitere Antworten (0)

Kategorien

Mehr zu Software Development Tools finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by