how to load image in different axes(axes1,axes2,axes3) using single pushbutton???...

조회 수: 1 (최근 30일)
I have to use two axes and two pushbutton to load the image.
_% --- Executes on button press in imagebtn.
function imagebtn_Callback(hObject, eventdata, handles)
[baseFileName,folder]=uigetfile('*.*','Specify an image file','on');
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
[baseFileName,folder]=uigetfile('*.*','Specify an image file','on');
But I saw the code for load different image using single button program source code in matlab. But sure I am not understand that code in some line in that program. I used that code But so many error occured. Reason i am not tell properly how to handle the axes. how to give the Tag name for Axes. For Example
% i think this the probles
handles.img=cell(1,length(File)); % what puropse using that img(handles.img)
for iFile=1:length(File)
end guidata(hObject,handles);
I got Following Error.
??? Cell contents reference from a non-cell array object.
Error in ==> Clrc>pushbutton2_Callback at 119 filename = fullfile(Folder, File{iFile});
Error in ==> gui_mainfcn at 96 feval(varargin{:});
Error in ==> arambam at 42 gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)arambam('pushbutton2_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback

채택된 답변

Image Analyst
Image Analyst 2013년 2월 6일
Well, . . . they're both bad. the first set of code calls the image array axes1 and axes2 - the same name that you're calling the axes. While this won't give an error it is confusing and bad practice. You should call them grayImage or rgbImage or some other descriptive name that's not the name of one of your GUI controls. You can use the same name in both functions since you seem to be keeping the image just as a local variable, local to that function and it vanishes when that function exits.
The second set of bad code overwrites the built in image() function by calling the image array "image" - again, very very bad practice. You never want to choose a variable name that is the same name as one of the built in functions.
But the reason for the error is this expression:
handles is a structure. It does not have a structure member (field) called "axes", much less one that is a cell array. If you were to want to do it that way, you'd have to use dynamic structure names, but that is complicated and confusing. If you have only a handful of axes to populate with images, then I'd recommend just setting the current axes with the axes() function, or with the 'parent' option of imshow(). If you will really have some variable number of axes, like dozens, then I'd recommend you create them on the fly with uicontrol() and get the handles into an array. Then you could index them in a loop.
  댓글 수: 2
ChristianW 2013년 2월 6일
편집: ChristianW 2013년 2월 6일
The Function findobj can also be used:
h = findobj(handles.figure1,'Type','axes');
for i = 1:2
pics{i} = imread('ngc6543a.jpg');
Image Analyst
Image Analyst 2013년 2월 6일
Yes, very nice. As long as the axes are arranged in the desired order/layout on the GUI, this will work nicely.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)


Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by