How to check if one file selected when using MultiSelection in matlab?
Mostrar comentarios más antiguos
I have a function that allow user to browse and choose some images like this
[filename, pathname, filterindex] = uigetfile( ...
{ '*.jpg;*.jpeg;*.png','Images (*.jpg, *.jpeg, *.png)'; ...
'*.*', 'All Files (*.*)'}, ...
'Choose Class 1 DataSet', ...
'MultiSelect', 'on');
And I take the browsed images in a cell array
ChosenImages = strcat(pathname,filename);
Now I have a problem, if the user entered one image only, it doesn't return this image as one cell, it return each character as cell, and when I use
length(ChosenImages);
it returns the number of chars in the link!
also I tried
ischar(ChosenImages{1})
to check if one cell is a cell or not but it gives me an error too.
What can I do to check if the user chosen one image or multiple images?
Respuesta aceptada
Más respuestas (2)
Walter Roberson
el 4 de Dic. de 2015
[filename, pathname, filterindex] = uigetfile( ...
{ '*.jpg;*.jpeg;*.png','Images (*.jpg, *.jpeg, *.png)'; ...
'*.*', 'All Files (*.*)'}, ...
'Choose Class 1 DataSet', ...
'MultiSelect', 'on');
filename = cellstr(filename);
%now filename is a cell array regardless of the number of selected files.
2 comentarios
Eslam Hamed
el 4 de Dic. de 2015
Ahmed Harun-Al-Rashid
el 4 de Nov. de 2016
Dear Roberson, I also get help to solve similar problem using your answer. Thank you so much.
Sincerely, Rashid
zhou
el 7 de Nov. de 2024
0 votos
filename = cellstr(filename); % convert char to cellstr
disp(length(filename))
Categorías
Más información sobre App Building en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!