【发布时间】:2023-03-03 17:57:01
【问题描述】:
我希望从一个文件夹中读取一组图像,然后将其存储在一个数组中,这样如果我询问imshow(imageArray(5)),它就会显示数组中的第 5 个图像。使用我从类似问题中找到的一些代码,到目前为止我有这个:
% 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
但是,当我这样做时,我收到以下错误:
无法执行分配,因为左侧和右侧有一个 不同数量的元素。
ImportTry 中的错误(第 16 行)imageArray(k) = imread(fullFileName);
如何使用单个索引来索引高维数组?
【问题讨论】:
标签: matlab image-processing data-storage