作业帮 > 综合 > 作业

MATLAB的一个小问题

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/15 10:45:58
MATLAB的一个小问题
Files = dir(fullfile('C:\Users\Administrator\Desktop\MIT人脸库\nonfaces\\','*.bmp'));
LengthFiles = length(Files);
imagearray = zeros(20,20,LengthFiles);
%Img=zeros(20,20)
for i = 1:LengthFiles;
imagearray(:,:,i)=imread(strcat('C:\Users\Administrator\Desktop\MIT人脸库\nonfaces\',Files(i).name));
%Imgs=rgb2gray(Img);
%imagearray(:,:,i)=Img;
end
我想将一个文件夹里的图片都读出来然后保存到一个三维数组里,图片是BMP格式的,大小是20*20的,为什么运行之后提示
Assignment has more non-singleton rhs dimensions than non-singleton
subscripts
第一行你笔误了.
Files = dir(fullfile('C:\Users\Administrator\Desktop\MIT人脸库\nonfaces\\','*.bmp'));
改成
Files = dir(fullfile('C:\Users\Administrator\Desktop\MIT人脸库\nonfaces\','*.bmp'));
试一下.多了一个'\'
再问: 这个不是问题关键呀,imagearray(:,:,i)=imread(strcat('C:\Users\Administrator\Desktop\MIT人脸库\nonfaces\',Files(i).name));这里老报那个错误,我看了半天也没有越界的啊
再答: 你确定你的人脸图是灰度图不是rgb图吗? 如果是rgb图 imagearray = zeros(20,20,LengthFiles); 这句要改成 imagearray = zeros(20,20,3,LengthFiles); imagearray(:,:,i)=imread(strcat('C:\Users\Administrator\Desktop\MIT人脸库\nonfaces\',Files(i).name)); 改成 imagearray(:,:,:,i)=imread(strcat('C:\Users\Administrator\Desktop\MIT人脸库\nonfaces\',Files(i).name));