load 4 images and display in 4 diff axes in GUI

1 vue (au cours des 30 derniers jours)
sha
sha le 14 Sep 2012
Commenté : Jan le 15 Mar 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!

Réponse acceptée

Jan
Jan le 14 Sep 2012
Modifié(e) : Jan le 14 Sep 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 commentaire
sha
sha le 25 Sep 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!

Connectez-vous pour commenter.

Plus de réponses (1)

ARUN Robert
ARUN Robert le 15 Mar 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 commentaire
Jan
Jan le 15 Mar 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?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by