combining multiple .asc files to generate multidimensional raster
Show older comments
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 Comment
Ameer Hamza
on 18 Oct 2020
Is importdata loading file correctly? You may try breakpoints to find the error: https://www.mathworks.com/help/matlab/matlab_prog/set-breakpoints.html.
Answers (1)
Ameer Hamza
on 18 Oct 2020
Edited: Ameer Hamza
on 18 Oct 2020
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');
Categories
Find more on Weather and Atmospheric Science in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!