How to save/load current MATLAB workspace in .mat file from app designer
18 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Voss
am 17 Nov. 2022
Bearbeitet: Voss
am 17 Nov. 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 Kommentar
Siehe auch
Kategorien
Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!