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
2020 年 10 月 18 日
Is importdata loading file correctly? You may try breakpoints to find the error: https://www.mathworks.com/help/matlab/matlab_prog/set-breakpoints.html.
回答 (1 件)
Ameer Hamza
2020 年 10 月 18 日
編集済み: Ameer Hamza
2020 年 10 月 18 日
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 Exchange で Weather and Atmospheric Science についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!