I am looking to read a set of images from a folder and then store it in an array such that if I ask imshow(imageArray(5))
it displays the 5th image in the array. Using some code I found from similar questions, I have this so far:
% Specify the folder where the files live.
myFolder = 'C:\Users\MyName\Documents\MATLAB\FolderName';
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.tif'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
imageArray = zeros(480, 1);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
imageArray(k) = imread(fullFileName);
end
However when I do this I get the following error:
Unable to perform assignment because the left and right sides have a different number of elements.
Error in ImportTry (line 16) imageArray(k) = imread(fullFileName);
How can I accomplish using a single index to index higher-dimensional arrays?