Filter löschen
Filter löschen

Read file, extract region and save

1 Ansicht (letzte 30 Tage)
Robert am 18 Apr. 2017
Kommentiert: Robert am 18 Apr. 2017
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!
  2 Kommentare
Image Analyst
Image Analyst am 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.
Robert am 18 Apr. 2017
Sorry I didn't include this information before.
The region to be identified need to be based on a fix range of latitudes and longitudes, to concatenate them into a 3-D array, as you mentioned.
Ideally adding something like this to the beginning of the code:
Lat_North = ??;
Lat_South= ??;
Long_West = ??;
Long_East= ??;
Original Longitude values goes from 1 to 1400, but need to be changed to degrees by using the function "wrapTo180". Then, Longitude values goes from 0.125 to 179.875 and then from -179.875 to -0.125, each 0.25 degrees (1440), as data start in Africa (west side of matrix, see attached figure (example.jpg) representing 1 day of data).
Latitude values goes from -89.875 to 89.875 (720).
I have also attached an example (example.mat) of the Longitude, Latitude, and Data, used to create attached figure.

Melden Sie sich an, um zu kommentieren.

Antworten (0)


Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by