load 4 images and display in 4 diff axes in GUI

1 次查看(过去 30 天)
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!

采纳的回答

Jan
Jan 2012-9-14
编辑:Jan 2012-9-14
  • "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 个评论
sha
sha 2012-9-25
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!

请先登录,再进行评论。

更多回答(1 个)

ARUN Robert
ARUN Robert 2017-3-15
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 个评论
Jan
Jan 2017-3-15
"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?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by