load 4 images and display in 4 diff axes in GUI

1 visualización (últimos 30 días)
sha
sha el 14 de Sept. de 2012
Comentada: Jan el 15 de Mzo. de 2017
Hi all,
i have created a button which will load images from the file. i needed to load 4 images and display them in 4 different axes in GUI. However, i have encountered some error in my final code.
--------------------------------------------------------------------
[MATLAB, folders] = uigetfile('*.*', 'MultiSelect', 'on')
filename1=strcat(folders,MATLAB(1))
filename2=strcat(folders,MATLAB(2))
filename3=strcat(folders,MATLAB(3))
image1=imread(filename1);
axes(handles.axes2)
imshow(image1)
handles.img=image1;
guidata(hObject, handles);
image2=imread(filename2);
axes(handles.axes3)
imshow(image2)
handles.img=image2;
guidata(hObject, handles);
image3=imread(filename3);
axes(handles.axes4)
imshow(image3)
handles.img=image3;
guidata(hObject, handles);
-----------------------------------------------------
Here's the error:
??? Conversion to logical from cell is not possible.
Error in ==> imread at 342 if (strfind(filename, '://'))
Error in ==> test2>pushbutton2_Callback at 100 image1=imread(filename1);
Error in ==> gui_mainfcn at 96 feval(varargin{:});
Error in ==> test2 at 42 gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)test2('pushbutton2_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback__
------------------------------------------------
PLS HELP!!
thanks!

Respuesta aceptada

Jan
Jan el 14 de Sept. de 2012
Editada: Jan el 14 de Sept. de 2012
  • "MATLAB" is a strange name for a file name. This is not an error, but confusing.
  • After importing several files, the output is a cell string. Then strcat(folders,MATLAB(1)) is a cell string also. But IMREAD requires a string. Solution:
filename1 = strcat(folders, MATLAB{1}); % curly(!) braces
  • When you want to import 4 images, using filename1 to filename3 misses one of them. Using a loop would be smarter. Suggestion:
[File, Folder] = uigetfile('*.*', 'MultiSelect', 'on');
handles.img = cell(1, length(File));
for iFile = 1:length(File)
filename = strcat(Folder, File{iFile});
image = imread(filename);
axes(handles.axes(iFile)); % Better use a vector to store handles
imshow(image);
handles.img{iFile} = image;
end
guidata(hObject, handles);
Note: Using handles.axes(i) is more flexible than inserting the index in the name as in handles.axes1.
  1 comentario
sha
sha el 25 de Sept. de 2012
Thanks Simon!
i managed to make all the 3 images to appear at 3 different axes! i have just edit the curly bracket and it works like a charm!

Iniciar sesión para comentar.

Más respuestas (1)

ARUN Robert
ARUN Robert el 15 de Mzo. de 2017
i need a help sir. i want to view all my different images for the folder in single GUI axes window plz help me to send the code sir plz
  1 comentario
Jan
Jan el 15 de Mzo. de 2017
"Send the code" is not the right option in a public forum which is based on sharing the solutions. Most of all I cannot guess, what "view in single GUI" means. Please open a new thread for a new question and explain your problem exactly. What have you tried so far and which problems occur?

Iniciar sesión para comentar.

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by