Matlab Error, Non-existent field, axes properties.

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??

 採用された回答

Chandra Kurniawan
Chandra Kurniawan 2012 年 1 月 14 日

1 投票

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);

5 件のコメント

Walter Roberson
Walter Roberson 2012 年 1 月 14 日
What is this "handles.output", and why are you setting it to be the pushbutton ??
Chandra Kurniawan
Chandra Kurniawan 2012 年 1 月 14 日
@Randy : also don't forget to check the tag of your axes.
Are you sure the component named axes2?
Chandra Kurniawan
Chandra Kurniawan 2012 年 1 月 14 日
@ Walter: thanks for reminding me about 'pushbutton'.
randy
randy 2012 年 1 月 14 日
Dear Mr. Chandra..
thanks for help.. yes.. i've checked the tag.. and from my first GUI, tag for axes2 is always missing when i reopen it, i think that's why axes2 will never exist.. and in the second GUI, it's works... thank you very much...
randy.
Chandra Kurniawan
Chandra Kurniawan 2012 年 1 月 14 日
Yes,
glad to help you.
sama-sama, mas..

サインインしてコメントする。

その他の回答 (1 件)

Jan
Jan 2012 年 1 月 14 日

1 投票

Obviously axes2 is not a field of handles. Most likely you've created the button's callback before the axes2-object. Then updating the handles dynamically would be a solution:
% --- Executes on button press in browse2.
function browse2_Callback(hObject, eventdata, handles)
[FileName,PathName] = uigetfile('*.jpg;*.png;*.tiff;','Select file');
handles = guidata(hObject); % Update
if ischar(FileName) % Better than FileName~=0 !
axes(handles.axes2)
...
"if FileName~=0" works, but is not smart: Internally this is equivalent to:
if all(FileName ~= char(0)) & ~isempty(FileName)
So better use "ischar(FileName)" or "isequal(FileName, 0)".

3 件のコメント

randy
randy 2012 年 1 月 14 日
thank you for the answer... since i'm new in matlab, it's a bit difficult to understand.. but I am very appreciate it..
but it's seems i have the same error..
i have used ischar(FileName), update the handles and got same problem...
i've tried to use isequal(FileName,0).. it's generated no error but axes to doesn't seem to show the picture...
what should i do..?
regards,
r4ndieL
Walter Roberson
Walter Roberson 2012 年 1 月 14 日
It appears that randy is using GUIDE. The callbacks generated by GUIDE automatically fetch the most-recently-updated version of guidata, so Jan's guidata() solution would not be expected to help.
We have not seen enough code to know that axes2 really exists.
randy
randy 2012 年 1 月 14 日
Dear Mr. Jan
i have rechecked my GUI and i thought it's weird because the "tag" for axis2 always missing when i reopen the GUI. so i created new one using Your method and Mr. Chandra's and both of it worked so good... thank you very much for help...
..oh.. and for Mr. Walter, i'm sorry for not paying attention to my answer so it's make you re edit it. thank you
Randy

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by