Hi, I know this question may have been answered in another MATLAB answers question, but I looked through many and didn't find one written in an easily understandable way for me. Essentially, I have two GUIs; one main one, and second GUI which is called via a pushbutton and holds 3 checkboxes whose values are converted into a matrix. This is my initialization code:
function Initialize_GUI(hObject,eventdata,handles)handles.X = 1;handles.Y = 1;handles.Z = 1;handles.KFlip = [handles.X handles.Y handles.Z];assignin('caller','tempHandles',handles); % Import values from above into the main GUI
evalin('caller','handles.KFlip = tempHandles.KFlip;') % Set value of handles.KFlip to the initialization value
evalin('caller','guidata(hObject, handles);') % Within the main GUI, update the handles structure with the new value of KFlip
evalin('caller','clear tempHandles'); % Erase tempHandles structure from main GUI
% Update handles structure
guidata(hObject, handles);
In the main GUI, handles.KFlip was pre-initialized as [0 0 0]. Thus, when I clicked the button for opening GUI2 (all that is in that callback is the name of GUI2), I thought that it would change these values to [1 1 1] in the main GUI since the code above would be evaluated in the context of the main GUI. In addition, I thought that it would simply modify the main GUI's handles by changing the one value.
Instead, I don't even think that the lines above touch the main GUI. When I ran the code
evalin('caller','handles')
In GUI2 to see what it thought it was, it simply yielded the UI Controls of GUI2 with the addition of the handles.KFlip value. It was neither the handles structure of the Main GUI (which holds many more fields) nor GUI2 (which should have included handles.X, handles.Y, etc.).
What should I do? Am I using evalin wrong? Is there a better way of doing this? If there is already an easy-to-understand explanation of automatically passing the variables, please simply post the link.
Best Answer