Store filename in cell array

1 visualización (últimos 30 días)
Lauryn Burleigh
Lauryn Burleigh el 14 de Ag. de 2017
Editada: Guillaume el 15 de Ag. de 2017
I am trying to gather all the .bmp files in a folder and store them in a cell array so they can be shuffled and shown at the appropriate time in a task (using Psychtoolbox3). I am using the following code provided in a previous question https://www.mathworks.com/matlabcentral/newsreader/view_thread/267529.
[listOfFiles, folder] = uigetfile ({'*.jpg';'*.bmp';'*.tiff'}, '
Select your image ', 'MultiSelect', 'on');
for j=1:length(listOfFiles)
fullFileName = fullfile(folder, listOfFiles{j});
imageArray = imread(fullFileName);
[rows columns numberOfColorBands] = size(imageArray);
figure;
imshow(imageArray);
message = sprintf('%s is %d by %d', fullFileName, rows, columns);
disp(message);
end
The only change I want to make is to automatically pull all the .bmp files instead of the user selecting them using uigetfile. I've tried a lot of options, such as using dir and converting to cell using strcat, using dir and converting using {___.name}, etc. but have had no luck. Most of the errors tell me there are too many output arguments, referring to [listOfFiles, folder], but if I alter this variable name, it does not register the name as a cell array.
I am using Matlab R2017a.
Any help would be greatly appreciated!!

Respuesta aceptada

Jan
Jan el 14 de Ag. de 2017
Editada: Jan el 14 de Ag. de 2017
DirList = dir(fullfile(folder, '*.bmp'));
listOfFiles = {DirList.name};
for j=1:length(listOfFiles)
fullFileName = fullfile(folder, listOfFiles{j});
...
  1 comentario
Guillaume
Guillaume el 15 de Ag. de 2017
Editada: Guillaume el 15 de Ag. de 2017
The loop is not even needed. fullfile happily works on cell arrays:
DirList = dir(fullfile(folder, '*.bmp'));
fullFileName = fullfile(folder, {DirList.name});

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Image display and manipulation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by