based on the output i want i select images from a folder.... sometimes i want to select one image sometimes more than one image.... so i used 'MultiSelect' option in uigetfile...... but when i use 'MultiSelect' option in uigetfile and select only one image i'm getting error.... how can i use this syntax for selecting both single image and multiple image..... please can someone help me.... please do reply....

 採用された回答

Image Analyst
Image Analyst 2013 年 4 月 9 日
編集済み: Image Analyst 2013 年 4 月 9 日

1 投票

selectedFiles = uigetfile('*.PNG', 'Multiselect', 'on')

その他の回答 (3 件)

Jan
Jan 2013 年 4 月 9 日
編集済み: Jan 2013 年 4 月 9 日

0 投票

You mentioned, that there is an error, but neither showed the code nor the error message. Therefore I guess, that you forgot to care about the type of the replied filename, which is a cell string, not a string. According to the doc text of uigetfile:
[filename, pathname] = uigetfile('*.m', 'Select a MATLAB code file', ...
'MultiSelect', 'on');
if isequal(filename, 0)
disp('User selected Cancel')
return;
end
for k = 1:length(filename)
disp(fullfile(pathname, filename{k}))
end
If this does not help, and for future questions also, please post the code and the error message. The less we have to guess, the easier is the creation of a helpful answer.
[EDITED] I cannot test it currently, but does uigetfile('Multiselect', 'on') reply a string instead of a cell string, if only one file has been selected? If so an additional line is needed:
[filename, pathname] = uigetfile('*.m', 'Select a MATLAB code file', ...
'MultiSelect', 'on');
if isequal(filename, 0)
disp('User selected Cancel')
return;
end
filename = cellstr(filename); % Care for the correct type
for k = 1:length(filename)
disp(fullfile(pathname, filename{k}))
end

6 件のコメント

Elysi Cochin
Elysi Cochin 2013 年 4 月 9 日
編集済み: Elysi Cochin 2013 年 4 月 9 日
sir my error is when i select one image.... if i select "Cancel" or more than one image it works fine...... but if i select only one image this is the error i'm getting....
??? Cell contents reference from a non-cell array object.
Error in ==> biasemain>Retrieval_pushbutton_Callback at 383
FileName = FileNames{K};
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> biasemain at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==>
@(hObject,eventdata)biasemain('Retrieval_pushbutton_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
Elysi Cochin
Elysi Cochin 2013 年 4 月 9 日
編集済み: Elysi Cochin 2013 年 4 月 9 日
sir cant we select one image with "MultiSelect" option?? is my error because of that??
when i select only one image and do
len = length(NegFileNames)
it showing 6 as output sometimes 7..... why it is like that?? and when it reaches the line
for K = 1 : length(FileNames)
FileName = FileNames{K};
revImage = imread([PathName FileName]);
end
it shows the above error i posted... why like this?? please do reply sir.....
Walter Roberson
Walter Roberson 2013 年 4 月 9 日
Use iscell() to determine whether you get a cell array or not.
Elysi Cochin
Elysi Cochin 2013 年 4 月 9 日
thank u sir.....
Jan
Jan 2013 年 4 月 9 日
What is "NegFileNames"? Without knowing, how it is created, I cannot guess, why it has 6 or 7 elements.
Did Image Analyst's answer solve your problem already? If not, why did you accept it?
Image Analyst
Image Analyst 2013 年 4 月 9 日
Like Jan said, knowing the error would have been nice since we'd know if the problem was in your calling uigetfile(), or if it was how you were processing the filename(s) afterwards. Please review this: http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer

サインインしてコメントする。

Ozan Oguz
Ozan Oguz 2013 年 6 月 12 日

0 投票

I have a question here (similar but there is an obvious difference):
I am using uigetfile / multiselect option. There are 3 possibilities:
1) Cancel or exit (output 0) 2) Select only one file (output as string) 3) Select multiple files (cell as array of strings)
As you will notice, they all give outputs in different formats.
I am putting names of selected files into a PopupList. If you decide to add a new file to the list, you again click a button of uigetfile. Get old list, add to the new selection...
Should I use several if cases and change formats of these outputs several times as needed? Or are there any other practical way.

2 件のコメント

Image Analyst
Image Analyst 2013 年 6 月 12 日
Yes, use an if to take different actions depending on whether 0, 1, or multiple filenames are returned.
Jan
Jan 2013 年 6 月 13 日
@Ozan Oguz: Please do not highjack a foreign question, but open a new thread instead. Note that you cannot accept an answer here, when you are not the author of the original question.

サインインしてコメントする。

Ozan Oguz
Ozan Oguz 2013 年 6 月 13 日

0 投票

People, I need this code to work correctly, but I couldn't manage it. Please help me! Don't say "read the relevant help files" etc.
old_list = get(interface.List,'String');
[selected_files,directory] = uigetfile({'*.unv';'*.uff'}, 'Select files to be used', 'Multiselect','on');
if (selected_files==0)
msgbox('You selected nothing, and it returned a zero without any characters around it.');
elseif (Logical something indicating that I selected only one file.)
msgbox('You selected only one file');
elseif (Logical something indicating that I selected multiple files at once.)
msgbox('You selected multiple files.');
end

3 件のコメント

Ozan Oguz
Ozan Oguz 2013 年 6 月 13 日
Ok, don't read the "old_list" line. Sorry for that.
Jan
Jan 2013 年 6 月 13 日
@Ozan Oguz: Please do not highjack a foreign question, but open a new thread instead. Note that you cannot accept an answer here, when you are not the author of the original question.
Othmane ELMOUATAMID
Othmane ELMOUATAMID 2018 年 7 月 20 日
@Ozan Oguz : try this code
[selected_files,directory] = uigetfile({'*.unv';'*.uff'}, 'Select files to be used', 'Multiselect','on');
if iscell(selected_files)
nbfiles = length(selected_files);
msgbox('You selected multiple files.');
disp(nbfiles);
elseif selected_files ~= 0
nbfiles = 1;
msgbox('You selected only one file');
disp(nbfiles);
else
nbfiles = 0;
msgbox('You selected nothing, and it returned a zero without any characters around it.');
disp(nbfiles);
end

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeApp Building についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by