Read file, extract region and save
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Image Analyst
il 18 Apr 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.
Risposte (0)
Vedere anche
Categorie
Scopri di più su Characters and Strings in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!