Reading GRiB2 files with Matlab

user2309188 picture user2309188 · Apr 23, 2013 · Viewed 17.2k times · Source

Are there any toolboxes, which allow reading GRIB2 data into Matlab?

An example (waves modeled by NOAA) could be GRIB2 available from ftp://polar.ncep.noaa.gov/pub/history/waves

Answer

Rich Signell picture Rich Signell · Apr 23, 2013

In NCTOOLBOX for Matlab, you can open a GRIB2 file just like a local NetCDF file or a remote OPeNDAP dataset:

% download data
! wget ftp://polar.ncep.noaa.gov/pub/history/waves/multi_1.at_4m.dp.200607.grb2

% create ncgeodataset object
nc=ncgeodataset('multi_1.at_4m.dp.200607.grb2');

% list variables
nc.variables

% create geovariable object
dirvar=nc.geovariable('Primary_wave_direction_degree_true_surface');

% get data at 1st time step
dir=dirvar.data(1,:,:);

% get grid at 1st time step
g=dirvar.grid_interop(1,:,:);

% plot
pcolorjw(g.lon,g.lat,dir);
title(datestr(g.time))

enter image description here