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?
0 个评论
回答(1 个)
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 Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!