Read file, extract region and save
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I am trying to read multiple .nc files (I know how to do this, see below), then extract a small region from each file (not familiar how to do this), save this region in a matrix (3D), close file and repeat this again, through all 37 (years) .nc files, in a loop. Each file size is 1440 x 720 x ## (Longitude x Latitude x TimeStep), where ## are the number of days (could go from 120 to 366), depending of year (first and last year have less days, and there are leap and non-leap years).
myFolder = 'C:\Data';
filePattern = fullfile(myFolder, '*.nc');
matFiles = dir(filePattern);
for k = 1:length(matFiles), %length(matFiles)=37
baseFileName = matFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
Data(:,:,k) = ncread(fullFileName,'VariableName');
end
I am missing the portion of how to extract a small region from each .nc file inside loop, and then how to add it (using cat function ?) to generate a 3D matrix with each TimeStep (day) from each of the 37 files.
Your comments and suggestions are welcome. Thanks!
2 commentaires
Image Analyst
le 18 Avr 2017
We don't know how the regions are to be identified. Do you want to hand-trace them? Do you want them identified by thresholding? I have no idea. Are the regions all rectangles of the same size? They'd better be if you want to concatenate them into a 3-D array. Maybe you could attach one of the files, or at least show us a screenshot of what they look like.
Réponses (0)
Voir également
Catégories
En savoir plus sur Characters and Strings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!