Skip to content

Instantly share code, notes, and snippets.

@jdherman
Created June 25, 2014 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdherman/1fb84b5e0d81a1f8a848 to your computer and use it in GitHub Desktop.
Save jdherman/1fb84b5e0d81a1f8a848 to your computer and use it in GitHub Desktop.
opening netcdf variables in matlab
clc; clear all;
% run ncdisp('data.nc') to view variables and dimensions
% and you get the following:
%
% ncdisp('data.nc')
% Source:
% D:\jon\datasets\NOAA NCDC Daily Precip\data.nc
% Format:
% classic
% Dimensions:
% WBAN = 1582
% T = 47846
% Variables:
% WBAN
% Size: 1582x1
% Dimensions: WBAN
% Datatype: int32
% Attributes:
% long_name = 'Station'
% gridtype = 0
% units = 'ids'
% T
% Size: 47846x1
% Dimensions: T
% Datatype: int32
% Attributes:
% pointwidth = 1
% long_name = 'time'
% add_offset = 2.4e+06
% calendar = 'standard'
% gridtype = 0
% units = 'julian_day'
% PRCP
% Size: 47846x1582
% Dimensions: T,WBAN
% Datatype: int16
% Attributes:
% missing_value = -1e+04
% scale_factor = 0.01
% units = 'inches'
% long_name = 'precipitation'
% Read in variables from file data.nc
PRCP = ncread('data.nc','PRCP');
% Now use PRCP[day,station] to access precip (inches)
% The other variables are just one-dimensional indices
% Perhaps these WBAN station numbers mean something ... (??)
WBAN = ncread('data.nc','WBAN');
T = ncread('data.nc','T'); % T is just the day index
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment