Passing Data between Apps in app designer - Table Data in app1 plotted in app2
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jake Keiper
el 1 de Feb. de 2021
Comentada: Adam Danz
el 20 de Feb. de 2024
Hello,
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/506553/image.png)
Could somone please help me with this? I can provide more details if necessary.
Thanks!
2 comentarios
Siavash
el 20 de Feb. de 2024
Hi, thank you for the information.
It worked for me as well.
I have another question: How can I close the window of the first app when the second one opens?
Adam Danz
el 20 de Feb. de 2024
> How can I close the window of the first app when the second one opens?
Use the close command and specify the app's figure handle.
close(app.UIFigure)
You could also use delete but this will not invoke the figure's closing function.
delete(app)
Respuesta aceptada
Adam Danz
el 1 de Feb. de 2021
Editada: Adam Danz
el 2 de Feb. de 2021
Attached are two very simple apps to demonstrate multiwindow apps in AppDesigner.
- After downloading both files, add the folder to your Matlab path and open demo_MainApp.
- 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.
end
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);
end
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
end
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;
end
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
5 comentarios
Adam Danz
el 5 de Feb. de 2021
Editada: Adam Danz
el 5 de Feb. de 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.
Eshanee Bhattacharjya
el 29 de Mzo. de 2023
Thank you so much for this detailed explanation and the commands - it works for me as well now :) Truly appreciate it, Adam!
Más respuestas (0)
Ver también
Categorías
Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!