我有18个带有名称(AA01,AA02,AA03 ...... AA18)的ascii文件,每个文件有5220行和9列。我正在尝试导入和读取此文件并将数据保存在尺寸为(5220 x 9 x 18)
的3D矩阵中我使用下面的代码,但它没有通过
Folder = 'D:\My_Files';
Pattern = fullfile(Folder, '*.*');
Files = dir(Pattern);
for k = 1 : length(Files)
baseFileName = Files(k).name;
fullFileName = fullfile(Folder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
end
答案 0 :(得分:1)
我假设文件名为(A1.out,A2.out,A3.out ... A18.out)。
Folder = 'D:\My_Files\';
numberOfFiles=18;
A=zeros(5520,9,numberOfFiles);
for i=1:numberOfFiles
fileLocation=strcat(Folder,'A',num2str(i),'.out');
An=load(fileLocation);
A(:,:,i)=An;
end
A
是尺寸为(5520x9x18)
更新:对于文件名(AA01,AA02,...... AA18),每个文件有三个字段data
(5520x9),colheaders
(1x9)和textdata
(1x9)[来自评论中的样本数据]
Folder = 'D:\My_Files\';
numberOfFiles=18;
A=zeros(5520,9,numberOfFiles);
for i=1:numberOfFiles
if (i<10)
fileLocation=strcat(Folder,'AA0',num2str(i));
else
fileLocation=strcat(Folder,'AA',num2str(i));
end
An=importdata(fileLocation);
A(:,:,i)=An.data;
end
A
是尺寸为(5520x9x18)