I am having an issue with a handles variable handles.scanOne
.
I initialize it handles.scanOne = struct([]);
. The relevant callback is
function getButton1_Callback(hObject, eventdata, handles)
loadText(handles, hObject, 1, 'Select the original scans')
loadAxes(handles, 1)
and loadText updates the handles variable while loadAxes uses the updated variable.
function loadText(handles, hObject, region, displayMessage)
...
...
handles.scanOne = struct('imageArray', imageArray, 'patientNumber', patientNumber, ...
'scanNumber', scanNumber, 'pathName', pathname, 'maxPixel', maxPixel);
guidata(hObject,handles)
However, when I test my GUI the first time the button callback, handles.scanOne is updated within loadText
, but is not updated for the entire structure. When I press the button again, handles.scanOne
is updated for the entire structure.
Edit: I think I might know the problem. The handles
structure passed into the button callback is still the original one. The handles
structure has been updated by loadText, but that new structure is not passed into anything in the button callback. The following link has a solution to my problem: http://www.mathworks.com/matlabcentral/answers/122423-gui-how-to-update-the-handles-when-calling-a-function-callback-inside-another-callback
I ended up not storing everything in the handles structures and instead used
setappdata(objectHandle, 'var', var)
andgetappdata(objectHandle, 'var')
. I no longer had to useguidata(hObject, handles)
as a result and it made thinking about the handles structure much easier.