Working With MERRA Data in Matlab

This section assumes that you are familiar with the Matlab interface and its basic commands, but have not yet used Matlab to work with NetCDF files.

Some commands that will be useful:

1. ncdisp(source)

Displays all information about what is contained in the NetCDF file including, but not limited to, variable names, variable sizes, dimensions, units, and missing value codes.

For example, typing the following into the command window:

ncdisp('MERRA300.prod.assim.tavg1_2d_slv_Nx.20091001.SUB.nc')

will print out:


This is useful to determine the variable names that you will need in order to read in the data to your workspace.

2. ncread(source,varname)

Reads in the specified variable name to the workspace.

For example,

lat=ncread('MERRA300.prod.assim.tavg1_2d_slv_Nx.20091001.SUB.nc','latitude')

will read in the the latitude values and save them to an array named “lat”.

Example Code


To use the above code:

Lines 16 and 17 - the date ranges of the data files you want to read in. If you only have one file then set a and b equal to the date of the file.

Line 38 - the location and name of your data files.

Caveats:

This script assumes a specific spatial range of 12×9 and a temporal range of 24 hours. Your ranges will be different depending on what MERRA datasets you are using and so you will have to adjust your code accordingly.

If you have any questions or need assistance, send me an email at daniel.burtch@my.und.edu