combining multiple .asc files to generate multidimensional raster

I have 5 of .asc files each of dimensions 18*34. I need to combine these files to generate a multidimensional matrix with dimensions 18*34*5.
I am using the following code; but the dimensions of output matrix are 1*1*5.
Where am I wrong?
path = 'E:\SPI';
Pattern = fullfile(path, 'CDR*');
Files = dir(Pattern);
A = [];
for k = 1 : length(Files)
baseFileName = Files(k).name;
fullFileName = fullfile(path, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
data = importdata(fullFileName);
A = cat(3, A, data);
save('A.mat','A');
end
size(A)

回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 10 月 18 日
編集済み: Ameer Hamza 2020 年 10 月 18 日

0 投票

Try this
path = 'E:\SPI';
Pattern = fullfile(path, 'CDR*');
Files = dir(Pattern);
A = cell(numel(Files));
for k = 1 : numel(Files)
baseFileName = Files(k).name;
fullFileName = fullfile(path, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
data = readmatrix(fullFileName);
A{k} = data;
end
A = cat(3, A{:})
save('A.mat','A');

カテゴリ

ヘルプ センター および File ExchangeWeather and Atmospheric Science についてさらに検索

質問済み:

2020 年 10 月 18 日

コメント済み:

2020 年 10 月 18 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by