How to save/load current MATLAB workspace in .mat file from app designer

18 visualizaciones (últimos 30 días)
I am develping a GUI that loads the necessary variables and inputs in MATLAB workspace and then runs a simulink model.
When everything is loaded with the assign function, I would like to save the current workspace with those variables, tables, etc from MATLAB workspace in a .mat file , equivalent to:
%% from MATLAB
save("This_workspace")
%%
So this was my approach:
%% properties (Access = private)
architecture_load
%% function SAVEButtonPushed(app, event)
app.architecture_load=get(app.UITable,'Data');
assignin("base",'architecture_load',app.architecture_load);
name_file = inputdlg("Save as");
if isempty(name_file)
return
else
save(append(name_file,".mat"));
end
end
And to load similarly...However, when this is commanded by the App I have the following error message:
Warning: Unable to save App Designer app object. Save not supported for matlab.apps.AppBase objects.
Because it tries to save the App workspace instead of MATLAB workspace...Any idea about how can I define a .mat file to SAVE / LOAD easily?

Respuestas (1)

Voss
Voss el 17 de Nov. de 2022
Editada: Voss el 17 de Nov. de 2022
To save your MATLAB (i.e., base) workspace to a mat file from within an app:
evalin('base',['save(''' name_file '.mat'');']);
However, you may consider saving just the variables you need from the app workspace, which would avoid the use of assignin and evalin. For instance, you can use whos to get a struct of information about every variable, then remove those variables (e.g., the app object itself) from the struct that you don't want to save, and save the remaining ones.
  1 comentario
Anoy Chowdhury
Anoy Chowdhury el 18 de Nov. de 2022
Thanks a lot! It did not really work but the idea helped me to find this one:
evalin('base',char(strcat({'save '},name_file)))

Iniciar sesión para comentar.

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by