MATLAB: Passing variables in GUI vs. assignin then evalin

guipassing variables

I've looked through multple ways to do this on the forum but I still can't seem to figure it out.
I'm loading a bunch of variables into my GUI that I want to be able to pass to different functions/callbacks (they are the same, right?).
In the past I have done this by:
[fname, path]=uigetfile('*.mat');
File = fullfile(path, fname);
load(File)
assignin('base','com',com);
assignin(many more)
and then in another callback:
com = evalin('base','com')
manymore = evalin('base','manymore')
How do I pass these individual variables between different callbacks so I don't have to always pass it throught the workspace and bring int back (also, what's wrong with doing it this way?)?
I know guidedata(hObject, handles) exist, but I can't for the life of me make it work.
Thanks

Best Answer

To answer the question of how to do it with guidata:
%this stores data to your figure:
guidata(hObject,handles)
%this retrieves that data:
handles=guidata(hObject)
In your function you can modify or create fields of the struct. If you modify data, don't forget to use the first to update the data stored with the figure.
You can treat the first line as a set() and the second line as a get(). If you have a GUI created with GUIDE the second line is implicitly executed every callback, so you'll only need to use the first line.