load 4 images and display in 4 diff axes in GUI

조회 수: 1 (최근 30일)
sha
sha 2012년 9월 14일
댓글: Jan 2017년 3월 15일
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