Read file, extract region and save
3 Ansichten (letzte 30 Tage)
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');
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!