How can I fill an array of images from inside a for loop?
Ältere Kommentare anzeigen
Hi all.
I'm trying to read a bunch of images of faces from a directory within the current directory into an accessible array I can use later on to display one of them randomly.
Here's what I've got so far:
FaceFolder = 'Faces';
if ~isdir(FaceFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', FaceFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(FaceFolder, '*.bmp');
bitmapFiles = dir(filePattern);
AllFaces=zeros(length(bitmapFiles), 638);
for k = 1:length(bitmapFiles)
baseFileName = bitmapFiles(k).name;
fullFileName = fullfile(FaceFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
currentim = imread(fullFileName);
AllFaces(k,:) = currentim;
end
I keep getting "Subscripted assignment dimension mismatch" errors for the AllFaces(k,:) = currentim; line.
638 is what I believe to be the size of one of the bitmap files (they're all the same dimensions) hence that number, so I tried using that to set up an array of zeros before the loop to fill it in but clearly I'm doing something wrong.
Anyone have any ideas?
Antworten (1)
Evan
am 17 Jun. 2013
It looks like you're trying to assign a [nxm] matrix (the image) to a [1xm] row in AllFaces. Instead, try this:
AllFaces(:,:,k) = currentim;
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!