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 Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by