MATLAB Answers

Passing Data between Apps in app designer - Table Data in app1 plotted in app2

36 views (last 30 days)
Jake Keiper
Jake Keiper on 1 Feb 2021
Edited: Adam Danz on 5 Feb 2021
I am trying to pass data from one applicationto another in matlab. Specifically, I am trying to pass the data that the user has defined in UITable data in the first app to a figure in the second app. I have gone through the documentation and the examples MATLAB provides. I have read through others solutions, and I truly do not understand the logic or the execution of this process.
Only column 2 in the UITable is relevant for the plot in the other application. Here are pictures of my setup. I blocked off the the other buttons and text to make it more simple. App 1 is the one with the table. App 2 is the one with the graph. When I press Visualize Structure in app1, app2 will be opened in order to plot the data from column 2.
Could somone please help me with this? I can provide more details if necessary.

Accepted Answer

Adam Danz
Adam Danz on 1 Feb 2021
Edited: Adam Danz on 2 Feb 2021
Attached are two very simple apps to demonstrate multiwindow apps in AppDesigner.
  1. After downloading both files, add the folder to your Matlab path and open demo_MainApp.
  2. From the demo_MainApp, press the button to open the second app.
4 Steps to exchange app handles between multiwindow apps
Open each attached app in AppDesigner to see these 4 steps taken so that both apps have access to both app handles.
1. In demo_MainApp, "app2" was declared as a private variable. You should use a better name, though.
properties (Access = private)
app2 = []; % handle to app2, evoked within this app.
2. In demo_MainApp, demo_SecondaryApp is evoked from a callback function. The main app handle is passed to the secondary app.
% Button pushed function: Call2ndappButton
function Call2ndappButtonPushed(app, event)
% Call app2
app.app2 = demo_SecondaryApp(app);
3. In demo_SecondaryApp, "app1" was declared as a private variable. You should use a better name, though.
properties (Access = private)
app1 = []; % handle to app1 which evoked this app
4. In demo_SecondaryApp, a second input was added to the startup function which recieves the main app handle. The main app handle is added as a property of the secondary app so all internal functions have access to it.
% Code that executes after component creation
function startupFcn(app, app1)
app.app1 = app1;
Note that the demo_MainApp handle is input #2 in the startup function of demo_SecondaryApp in step 4 but it appears to be input #1 when it's called from demo_MainApp in step 2. That throws some people off. When an app is evoked, the first input is added internally.
More info
Adam Danz
Adam Danz on 5 Feb 2021
>[ in step 4 ] is app1 (on the right side of the equal sign) a general variable that MATLAB recognizes? Like for instance, if an application (or several applications) is open, then the first application is app1 and the second would be app2?
No. You could test that to find the answer. Notice in steps 1 and 3 I suggest you rename the vars app1 and app2. Those were names I choose for the example.
% for example,
function startupFcn(app,tableApp)
> is there going to be other instances off communicating where this approach is not valid (are there any limitations to this)
I'm not sure what that means. In general those are the 4 steps needed to shareany variable between apps.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!