How to save all variables in the matlab base workspace by a button in App?

5 views (last 30 days)
Hello, I use "assignin" to write the variable created in App designer to the workspace, but I also manually type the code or formula in the command window to calculate, and thus create more variables.
I want to save all these variables in the workspace. I can use "save('C:\test.mat')" in the command window with no problem. I also have a save button in the app, which is supposed to do the same thing (save all variables in the matlab workspace).
With save('C:\test.mat') by the button, app designer will save all variables in both matlab workspace and the app desinger workspace, and then get a warning that Unable to save App Designer app object. Save not supported for matlab.apps.AppBase objects.
My question is how to save all these variables only in the matlab workspace?
Edit: matlab workspace means the base one

Accepted Answer

Matt J
Matt J on 17 Dec 2022
Edited: Matt J on 17 Dec 2022
It is not clear what you mean by, "the Matlab workspace". I will assume you mean the base workspace, i.e., the workspace of the command window. In your save button's callback, you would need,
str= "save('C:\test.mat')";
evalin('base',str)
  2 Comments
Tianlun Yu
Tianlun Yu on 17 Dec 2022
Hello Matt, thank you for pointing out the correct name. Yes, I meant the base workspace of the command window, and you solved my problem.
Matt J
Matt J on 17 Dec 2022
You're welcome, but if it did solve your problem, please Accept-click the answer.

Sign in to comment.

More Answers (0)

Categories

Find more on Entering Commands in Help Center and File Exchange

Tags

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!