MATLAB: Matlab Error, Non-existent field, axes properties.

axeserrorhandlesImage Processing ToolboxMATLABmultiple axesnon-existent field

hello,…
i've got some home work n' i'm working with 2 axes (axes1, axes2), 2 push button (browse1, browse2) made by guide… when i push the button, i want to put an image to each axes (browse1 for axes1, browse2 for axes2) i've done it but i got some error
here's my code:
% --- Executes on button press in browse1.
function browse1_Callback(hObject, eventdata, handles)
[FileName,PathName] = uigetfile('*.jpg;*.png;*.tiff;','Select file');
if(FileName~=0)
axes(handles.axes1)
handles.gambar=imread(fullfile(PathName, FileName));
image(handles.gambar)
axis off
else
return
end
guidata(hObject, handles);
% --- Executes on button press in browse2.
function browse2_Callback(hObject, eventdata, handles)
[FileName,PathName] = uigetfile('*.jpg;*.png;*.tiff;','Select file');
if (FileName~=0
axes(handles.axes2)
handles.gambar=imread(fullfile(PathName, FileName));
image(handles.gambar)
axis off
else
return
end
guidata(hObject, handles);
and the generated error:
??? Reference to non-existent field 'axes2'.
error in line 107 => axes(handles.axes2)
i thought, it's because handles cannot read existence of axes2, i have checked it in property insp. but i still don't know what is the problem…. is there some properties of axes2 i missed??

Best Answer

Hi,
in the pushbutton1 callback you should write :
function browse1_Callback(hObject, eventdata, handles)
handles.output = hObject;
[FileName,PathName] = uigetfile('*.jpg;*.png;*.tiff;','Select file');
if(FileName~=0)
axes(handles.axes1)
handles.gambar=imread(fullfile(PathName, FileName));
image(handles.gambar)
axis off
else
return
end
guidata(hObject, handles);
in the pushbutton2 callback you should write :
function browse2_Callback(hObject, eventdata, handles)
handles.output = hObject;
[FileName,PathName] = uigetfile('*.jpg;*.png;*.tiff;','Select file');
if (FileName~=0)
axes(handles.axes2)
handles.gambar=imread(fullfile(PathName, FileName));
image(handles.gambar)
axis off
else
return
end
guidata(hObject, handles);