MATLAB: Help required urgently about this error “REFERENCE TO NON EXISTENT FIELD”

errorguiimage processingurgent

im currently working on this thing which converts an rgb image to indexed when i press pushbutton 2 and then it will convert the map to ycbcr when i'll press pushbutton 3 but when i press pushbutton 3 it gives an error "106 inmap = handles.indmap; ??? Reference to non-existent field 'indmap'."
code is this :
% — Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles) % hObject handle to pushbutton2 (see GCBO) % eventdata reserved – to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
rgb=imread('C:\Users\Rao\Desktop\unused icons\backgrounds\birdie.png');
[handles.indexed,handles.indmap]=rgb2ind(rgb,8);
axes(handles.axes2);
imagesc(handles.indexed);
colormap(handles.indmap);
% — Executes on button press in pushbutton3. function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO) % eventdata reserved – to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
handles.ycbcrmap = rgb2ycbcr(handles.indmap);
axes(handles.axes3);
imagesc(handles.indexed);
colormap(handles.ycbcrmap);

Best Answer

you have to save the handles structure at the end of the callback if you want to store something in there. At the end of pushbutton2_Callback add:
guidata(gcbo,handles)
(I'm not a big fan of storing your data in the handles structure, but that's a different discussion ;) ).
Related Question