Try using ncdisp first to look at the structure of your file. Usually, netcdf files have data defined on 'dimension' variables - lat and lon. So you would first read the lat and lon variables from the file ( ncread ). >> lon = ncread('/tmp/example.nc','longitude')'
lon =
Columns 1 through 11
104.1250 104.3750 104.6250 104.8750 105.1250 105.3750 105.6250 105.8750 106.1250 106.3750 106.6250
Columns 12 through 13
106.8750 107.1250
>> lat = ncread('/tmp/example.nc','latitude')'
lat =
Columns 1 through 11
8.1250 8.3750 8.6250 8.8750 9.1250 9.3750 9.6250 9.8750 10.1250 10.3750 10.6250
Column 12
10.8750
You would then have to find the indices into lat and lon variables within which your grid lies. Use FIND to locate those indices:
>> latstart = find(lat>9.84,1, 'first')
latstart =
8
>> latend = find(lat<10.02,1, 'last')
latend =
8
Once you get these start/end indices to each of your variable dimension, you can use the partial read capability of NCREAD to read from your 'r' variable.
If you have to do this kind of operation frequently, consider wrapping this logic in a function.
(Note - have a look at the linked functions and examples. Give it a try and post back if you have trouble adapting this idea).
Best Answer