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

5 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Matt J
Matt J am 17 Dez. 2022
Bearbeitet: Matt J am 17 Dez. 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 Kommentare
Tianlun Yu
Tianlun Yu am 17 Dez. 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 am 17 Dez. 2022
You're welcome, but if it did solve your problem, please Accept-click the answer.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Entering Commands finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by