MATLAB Answers


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

on 6 Feb 2013

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

1 Answer

Answer by Image Analyst
on 6 Feb 2013
 Accepted answer

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.


The Function findobj can also be used:

h = findobj(handles.figure1,'Type','axes');
for i = 1:2
    pics{i} = imread('ngc6543a.jpg');

Yes, very nice. As long as the axes are arranged in the desired order/layout on the GUI, this will work nicely.

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!