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

18 次查看(过去 30 天)
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?

回答(1 个)

Voss
Voss 2022-11-17
编辑:Voss 2022-11-17
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.

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by