How to store data from DialogApp in CallingApp while closing the DialogApp in App Designer?
Show older comments
Hi,
I have a Push Button function in an App, that opens a DialogApp with two spinners and runs a seperate Matlab function thereafter.
What I want from the DialogApp is to store these two values in the main App/insert them into the function and then close the Dialog Window before/while the function runs and populates the axes in the main App.
I managed to create a Push Button in the main App, that opens both the dialog window and runs the function, but it does not populate the function with the two desired values from the DialogApp.
function PushButtonPushed(app, event)
% Disable Plot Options button while dialog is open
app.PushButton.Enable = 'off';
% Call dialog box with input values
dby=1;compass=0;
app.DialogApp = DialogApp(app,dby,compass);
[app.x,app.y,app.z,app.N,app.E,app.Up,app.P,app.Q,app.Upak,app.Lpak,app.t2,app.t4]=my_function(dby,compass);
plot(app.pq_axes, app.t4,app.P)
plot(app.packer_axes, app.t4,app.Upak,app.t4,app.Lpak)
app.PushButton.Enable = 'on';
end
Can someone tell me how to store the values from the DialogApp in the main App so that the function can use them?
Thank you!
1 Comment
Answers (1)
Follow this demo (attached). If you have any trouble, let us know where you're at and we can help you get unstuck.

- App1 generates a random number when opened and contains a button to open App2.
- The starting function for App2 includes a 2nd input for the App1 handle.
- When App2 is opened, it uses the App1 handle to extract the random number from App1 and copies it to App2.
Here are the steps taken for App2 to get data from App1
1. In App2: Add a startup function and add a 2nd input to the startup function. The first condition below closes App2 if it's not opened with a second input. This condition could be even more strict and require the 2nd input to be the handle specifically to App1. Next, the random number of App1 is extracted and copied to App2.
% Code that executes after component creation
function app2StartupFcn(app, app1Handle)
% Requires 2nd input; throw error if missing or empty
if nargin < 2 || isempty(app2Handle)
close(app.UIFigure)
error('App2 must be opened by App1.')
end
% Get app1 random variable value
app1RandVar = app1Handle.RandomnumberEditField.Value;
% Set app2
app.Randomnumberfromapp1EditField.Value = app1RandVar;
end
2. In App1: The push button is assigned a callback function to open App2 and includes the handle to App1 in the 2nd input.
function Openapp2ButtonPushed(app, event)
app2(app)
end
2 Comments
Adam Danz
on 10 Sep 2021
You can still use the logic in my answer with some minor additions.
Step 2 of my answer opens app2 and passes the handle from app1 to app2.
When you insert a value into app2, the callback function that responds to the the changed value can store the data in app1 using the app handle.
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!