MATLAB: How to extract data from .nc file based on latitude, longitude, time and wind

netcdftime

Hello,
This is my first time trying to pull data from an netCDF file using MATLAB…
here's what I did…
clear all
close all
ncid = netcdf.open('uwnd.sig995.2016.nc','NC_NOWRITE');
lat = netcdf.getVar(ncid,0);
whos lat
lon = netcdf.getVar(ncid,1);
whos lon
time = netcdf.getVar(ncid,2);
whos time
wind = netcdf.getVar(ncid,3); %var3 wind 4x day
whos wind
latlim = [5 -5]; %5N 5S
lonlim = [-50 -45]; %-50W -45W
I dont know how to extrat one year for exemple 2016:
timelim = [ ? ]
and the wind for these lat lon and time…
Any help?
Thx in advance! Regards.
Below the data:
Format:
netcdf4_classic
Global Attributes:
Conventions = 'COARDS'
title = '4x daily NMC reanalysis (2014)'
history = 'created 2013/12 by Hoop (netCDF2.3)'
description = 'Data is from NMC initialized reanalysis
(4x/day). These are the 0.9950 sigma level values.'
platform = 'Model'
References = 'http://www.esrl.noaa.gov/psd/data/gridded/data.ncep.reanalysis.html'
dataset_title = 'NCEP-NCAR Reanalysis 1'
Dimensions:
lat = 73
lon = 144
time = 1460 (UNLIMITED)
Variables:
lat
Size: 73x1
Dimensions: lat
Datatype: single
Attributes:
units = 'degrees_north'
actual_range = [9.00e+01 -9.00e+01]
long_name = 'Latitude'
standard_name = 'latitude'
axis = 'Y'
lon
Size: 144x1
Dimensions: lon
Datatype: single
Attributes:
units = 'degrees_east'
long_name = 'Longitude'
actual_range = [0.00e+00 3.58e+02]
standard_name = 'longitude'
axis = 'X'
time
Size: 1460x1
Dimensions: time
Datatype: double
Attributes:
long_name = 'Time'
delta_t = '0000-00-00 06:00:00'
standard_name = 'time'
axis = 'T'
units = 'hours since 1800-01-01 00:00:0.0'
actual_range = [1.88e+06 1.89e+06]
uwnd
Size: 144x73x1460
Dimensions: lon,lat,time
Datatype: single
Attributes:
long_name = '4xDaily u-wind at sigma level 995'
units = 'm/s'
precision = 2
least_significant_digit = 1
GRIB_id = 33
GRIB_name = 'UGRD'
var_desc = 'u-wind'
level_desc = 'Surface'
statistic = 'Individual Obs'
parent_stat = 'Other'
missing_value = -9.97e+36
valid_range = [-1.02e+02 1.02e+02]
dataset = 'NCEP Reanalysis'
actual_range = [-3.45e+01 3.71e+01]

Best Answer

Your data is not arranged by year, it is arranged by time.
You will need to retrieve the Time vector. According to the notes it is in 'hours since 1800-01-01 00:00:0.0' . So divide that by 24 (to get days) and add datenum('1800-01-01 00:00:0') to get a result which is in MATLAB datenum format. Use datevec() to convert those values into arrays with year, month, day, hour, minute, second components. Compare to the desired year(s) to find the indices of the entries of interest. Then, use those indices to access the third dimension of the uwnd data in order to get the data for those times.
Related Question