How to save/load current MATLAB workspace in .mat file from app designer
18 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Voss
il 17 Nov 2022
Modificato: Voss
il 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.
Vedere anche
Categorie
Scopri di più su Develop Apps Using App Designer in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!