Update UIAxes in App1 after computation in App2

2 vues (au cours des 30 derniers jours)
GMabilleau
GMabilleau le 3 Sep 2024
Modifié(e) : Voss le 3 Sep 2024
Hello !
In App designer, I have built App1 and App2. In App1, I have a UIAxes and a button which, when activated, is used to plot the x and y variables in the UIAxes. I also have a second button that opens a second application (App2). In App2 I have a button which, when pressed, changes the value of y. I would now like to update App1's UIAxes with the new y value.
I've attached the App1 and App2 files with the associated code. When I press the button in App2, I get the following error message:
Unrecognized method, property, or field 'UIAxes' for class 'matlab.ui.Figure'.
Error in app2/ComputeButtonPushed (line 30)
plot(app.app1handle.UIAxes, app.x, app.y);
Error in matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 62)
newCallback = @(source, event)executeCallback(ams, ...
Error while evaluating Button PrivateButtonPushedFcn.
Any help would be appreciated.

Réponse acceptée

Voss
Voss le 3 Sep 2024
Modifié(e) : Voss le 3 Sep 2024
% Button pushed function: GotoApp2Button
function GotoApp2ButtonPushed(app, event)
app.app1handle = findall(0, 'Name', 'MyApp'); % MyApp is the App's fig name
app2handle = app2;
app2handle.app1handle = app.app1handle;
end
findall will return the UIFigure, not the app object. The UIFigure doesn't have a 'UIAxes' field (the app does), so that's the reason for the error.
Rather than doing what you're trying to do there, pass app1 (the entire app object) as an argument to app2. This way, any code in app2 that needs information from app1 can access it (because you store app1 as a property of app2).
This requires adding an input argument to app2 (which can be done by clicking the "App Input Arguments" button in the App Designer toolstrip when app2 is the active app in App Designer); you can call the new input argument "app1".
Then, the GotoApp2ButtonPushed function can simply be:
% Button pushed function: GotoApp2Button
function GotoApp2ButtonPushed(app, event)
app2(app); % call app2 with this app (app1) as an input argument
end
And app2's startupFcn becomes:
% Code that executes after component creation
function startupFcn(app, app1)
app.x = evalin('base','x');
app.y = evalin('base','y');
app.app1handle = app1; % store app1 as a property of this app (app2)
end
Note the new second input there, which is app1.
I've made those changes and the mlapp files are attached. It seems to work as intended now.

Plus de réponses (0)

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by