- 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.
How to store data from DialogApp in CallingApp while closing the DialogApp in App Designer?
11 views (last 30 days)
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
app.DialogApp = DialogApp(app,dby,compass);
app.PushButton.Enable = 'on';
Can someone tell me how to store the values from the DialogApp in the main App so that the function can use them?
Adam Danz on 7 Sep 2021
Edited: Adam Danz on 8 Sep 2021
Follow this demo (attached). If you have any trouble, let us know where you're at and we can help you get unstuck.
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)
error('App2 must be opened by App1.')
% Get app1 random variable value
app1RandVar = app1Handle.RandomnumberEditField.Value;
% Set app2
app.Randomnumberfromapp1EditField.Value = app1RandVar;
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)