I wrote an image browser using GUIDE (Matlab 2014a). Originally, one of the function callback looks like this, and it worked.
function btnLineProfileXY_Callback(hObject, eventdata, handles) figure(4);hold off; imshow(squeeze(handles.FRET(:,:,getappdata(handles.figure1,'Zind'),:))); hold on; handles.hL1 = line(getappdata(handles.figure1,'Xind')*[1 1],[1 handles.Ynum]); handles.hL2 = line([1 handles.Xnum], getappdata(handles.figure1,'Yind')); lineBtnDownFcn(handles); guidata(hObject, handles);
But then because many other callbacks use the same codes, so I decided to write a helper function for these repetitive codes.
function btnLineProfileXY_Callback(hObject, eventdata, handles) figure(4);hold off; imshow(squeeze(handles.FRET(:,:,getappdata(handles.figure1,'Zind'),:))); hold on; lineRoutine(handles); lineBtnDownFcn(handles); guidata(hObject, handles); function lineRoutine(handles) % Helper function
figure(4);hold off; imshow(squeeze(handles.FRET(:,:,getappdata(handles.figure1,'Zind'),:))); hold on; handles.hL1 = line(getappdata(handles.figure1,'Xind')*[1 1],[1 handles.Ynum]); handles.hL2 = line([1 handles.Xnum], getappdata(handles.figure1,'Yind')); guidata(handles.figure1, handles);
When structured like this, it doesn't work anymore. The line object handles are not save to the handles structure. The function call was successful and there was no error message generated. But when I examine the handles structure after the function call, there was no handles.hL1 and handles.hL2. What did I do wrong?
Best Answer