combining multiple .asc files to generate multidimensional raster
Mostrar comentarios más antiguos
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 comentario
Ameer Hamza
el 18 de Oct. de 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.
Respuestas (1)
Ameer Hamza
el 18 de Oct. de 2020
Editada: Ameer Hamza
el 18 de Oct. de 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');
Categorías
Más información sobre Weather and Atmospheric Science en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!