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

New to MATLAB?

how to load image to two axes with use of one push button

Asked by Fathima Haleema

Fathima Haleema (view profile)

on 5 Feb 2013

Dear friends

I have to create color constancy program for using GUI in mat lab i want to load two images for using two axes(axes1,axes2) with the use of one pushbutton1(LoadImage) i have to try that following code

[File,Folder]=uigetfile('*.*','Multiselect','on');
handles.img=cell(1,length(File));
for iFile=1:length(File)
     filename=strcat(Floder,File{iFile);
     image=imread(filename);
     axes(handles.axes(iFile));
     imshow(image);
     handles.img{iFile} =image;
end
     guidata(hObject,handles);

Please any one help to me. How to execute that code ?

0 Comments

Fathima Haleema

Fathima Haleema (view profile)

1 Answer

Answer by Walter Roberson

Walter Roberson (view profile)

on 5 Feb 2013
Accepted answer

In the line

   filename=strcat(Floder,File{iFile);

you have spelled Folder incorrectly, and you missed a '}', and you left out the '/' or '\' between the folder name and the file name.

It is safer to use fullfile() instead of building the name yourself:

filename = fullfile(Folder, File{iFile});

2 Comments

Fathima Haleema

Fathima Haleema (view profile)

on 5 Feb 2013

Oh Sorry Sir. Thank You Sir. I will use your code.

Fathima Haleema

Fathima Haleema (view profile)

on 5 Feb 2013

i have to apply your suggestion but i got the following error result

??? Cell contents reference from a non-cell array object.

Error in ==> colrc>imagebtn_Callback at 84 filename=fullfile(Folder,File{iFile});

Error in ==> gui_mainfcn at 96 feval(varargin{:});

Error in ==> colrc at 42 gui_mainfcn(gui_State, varargin{:});

Error in ==> @(hObject,eventdata)colrc('imagebtn_Callback',hObject,eventdata,guidata(hObject))

??? Error while evaluating uicontrol Callback

Code: function imagebtn_Callback(hObject, eventdata, handles)

% hObject handle to imagebtn (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

[File,Folder]=uigetfile('*.*','Multiselect','on');

handles.img=cell(1,length(File));

for iFile=1:length(File)

    filename=fullfile(Folder,File{iFile});
    image=imread(filename);
    axes(handles.axes{iFile});
    imshow(image);
    handles.img{iFile}=image;
end
    guidata(hObject,handles);
Walter Roberson

Walter Roberson (view profile)

Contact us