MATLAB Answers

How to save variables from within an app created in App Designer to use the variable from other function or script?

439 views (last 30 days)
How to save variables from within an app created in App Designer to use the variable from other function or script? I want to save these variables when I close the app.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 7 Aug 2018
There are three approaches that you can utilize for using data from an app created using App Designer in a different function or script. All these methods are based on saving the data from the app to the MATLAB Workspace, which the other function or script can access.
1. Using "assignin" to assign the value of the desired variable in the workspace. You can refer to the following documentation link for an example:
2. Using "export2wsdlg" to export variables to workspace :
3. Finally, you can also save the desired variables in a MAT file using the "save" command and then load the variables in the other function or script using the "load" command:
You can use any of the above approaches inside of the "CloseRequestFcn" such that when the app is closed the variables will be saved as the "CloseRequestFcn" is executed. Here is an example of using the "CloseRequestFcn" for a figure :
  1 Comment
Javier Mancheño Devis
Javier Mancheño Devis on 16 Jul 2021 at 9:39
I'm having problems saving variables from the App into a MAT file. I export these variables to the base workspace using "export2wsdlg", but when I try to save the base workspace from the App it only saves the workspace on which the App is working, not the base workspace. I would like to directly save the variables through the GUI and not have to use the save function through the command line.

Sign in to comment.

More Answers (0)

Products


Release

R2016b

Community Treasure Hunt

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

Start Hunting!