Hi: I made a little GUI to classify images in a directory. It shows the user the images, and there is an edit box in which the user may type what the image is, after hitting enter, the text in the box is supposed to be saved to handles. The contents of the edit box are saved to handles thusly:
function count_KeyPressFcn(hObject, eventdata, handles)% hObject handle to count (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA
handles = guidata(hObject);keypress=get(handles.figure1,'currentcharacter');if isequal(keypress,char(13)) % Enter key is pressed
handles.id(handles.index).keypress=get(hObject,'String'); %get contents of edit box
handles.index=handles.index+1; % indexing for files - so to open next file in list.
guidata(hObject, handles); idgui_showim(hObject, eventdata, handles); %This shows the next picture and empties out the edit box.
end
It'll cycle through the images just fine, but when the callback to save it is triggered (with a save button), the handles.id.keypress structure is empty (it is initialized to be an empty char array with the same length as the number of files in the directory). The handles.index value is correct though (e.g. if I look at 8 images it'll read 8).
I added the handles = guidata(hObject); line after searching around and thinking that I was not getting the updated handles, but that doesn't seem to be the problem.
The truly baffling thing is that if I set a breakpoint on the "handles.id(handles.index).keypress=get(hObject,'String');" line I can see the text I've typed showing up in handles.id.keypress as I cycle through, and then when I hit the save button, handles.id.keypress is not empty – everything is where it should be. But if I remove that breakpoint, then handles.id.keypress is always empty when the save button callback is triggered.
I'm quite confused at this point. Anyone have any thoughts on what's happening?
Thanks, Rob
Best Answer