Discussion:
SAVE GUI TO WORKSPACE
(too old to reply)
Gaurav Gehani
2009-04-27 04:00:19 UTC
Permalink
hi guys,
is it possible to save every variable in my gui to my base workspace ? although assignin command is there but it can save only one variable at a time s othat would be too tedious to use, i want tosave all variable in one go or if i can pass all variable from one function to another in my gui only. Assuming i have large number of variables (around 100)
v***@gmail.com
2009-04-27 04:04:48 UTC
Permalink
Post by Gaurav Gehani
hi guys,
is it possible to save every variable in my gui to my base workspace ? although assignin command is there but it can save only one variable at a time s othat would be too tedious to use, i want tosave all variable in one go or if i can pass all variable from one function to another in my gui only. Assuming i have large number of variables (around 100)                
keep all the variables into a structure variable and save the
structure variable.
use "save" and "load" commands.
Gaurav Gehani
2009-04-27 06:46:03 UTC
Permalink
Hi doing save and load wont it make system too slow because of hard disk accesses..
I am trying to save all variables in worksapce by

assignin('base','myvars',mywars); //myvars is my struct name keeping both same on both workspace

but when i move to next function and try to do


assignin('caller','myvars',myvars); i get error that myvars is undefined, what do i do to ignore this or overcome this
v***@gmail.com
2009-04-27 04:04:48 UTC
Permalink
Post by Gaurav Gehani
hi guys,
is it possible to save every variable in my gui to my base workspace ? although assignin command is there but it can save only one variable at a time s othat would be too tedious to use, i want tosave all variable in one go or if i can pass all variable from one function to another in my gui only. Assuming i have large number of variables (around 100)                
keep all the variables into a structure variable and save the
structure variable.
use "save" and "load" commands.
Sanketh
2010-05-04 06:50:08 UTC
Permalink
Hi Gaurav,
You can probably try this work around:
Save all the variables in you function to the current directory as a .mat file and then load the .mat file from the base using evalin. For example:

function [ output_args ] = yourfunction( inputfilename )
%
%Codes where your variables are generated
%
save('tempmatfile.mat');%Save the variables in the function as a .mat file.
evalin('caller','load(''tempmatfile.mat'')');%Load the .mat file in base
delete('tempmatfile.mat');%Delete the temporary .mat file
Sanketh
2010-05-04 06:50:08 UTC
Permalink
Hi Gaurav,
You can probably try this work around:
Save all the variables in you function to the current directory as a .mat file and then load the .mat file from the base using evalin. For example:

function [ output_args ] = yourfunction( inputfilename )
%
%Codes where your variables are generated
%
save('tempmatfile.mat');%Save the variables in the function as a .mat file.
evalin('caller','load(''tempmatfile.mat'')');%Load the .mat file in base
delete('tempmatfile.mat');%Delete the temporary .mat file
t***@gmail.com
2013-10-30 12:39:40 UTC
Permalink
Post by Sanketh
Hi Gaurav,
function [ output_args ] = yourfunction( inputfilename )
%
%Codes where your variables are generated
%
save('tempmatfile.mat');%Save the variables in the function as a .mat file.
evalin('caller','load(''tempmatfile.mat'')');%Load the .mat file in base
delete('tempmatfile.mat');%Delete the temporary .mat file
Thanks you so much for revealing such a simple and brilliant code. You saved my ass today. I have been searching how to load mat file saved from one gui into another gui's base workspace for all day and couldn't find anything worked out. Keep that work up!!!! ^^
Steven Lord
2013-10-30 13:32:13 UTC
Permalink
Post by t***@gmail.com
Post by Sanketh
Hi Gaurav,
Save all the variables in you function to the current directory as a .mat
function [ output_args ] = yourfunction( inputfilename )
%
%Codes where your variables are generated
%
save('tempmatfile.mat');%Save the variables in the function as a .mat file.
evalin('caller','load(''tempmatfile.mat'')');%Load the .mat file in base
delete('tempmatfile.mat');%Delete the temporary .mat file
Thanks you so much for revealing such a simple and brilliant code. You
saved my ass today. I have been searching how to load mat file saved from
one gui into another gui's base workspace for all day and couldn't find
anything worked out. Keep that work up!!!! ^^
There is only one base workspace in a session of MATLAB. This code permits
any program that has access to the base workspace (i.e. all of them, through
the use of EVALIN or ASSIGNIN) to "fiddle" with your GUI's internal
information.

Take a look at this section of the documentation for alternatives that you
can use to pass data between the GUIs in a way that's harder for other
programs to interfere with.

http://www.mathworks.com/help/matlab/creating_guis/making-multiple-guis-work-together.html
--
Steve Lord
***@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com
Loading...