View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Read netCDF files and display variable information

4.0 | 2 ratings Rate this file 9 Downloads (last 30 days) File Size: 1.72 KB File ID: #31284 Version: 1.8

Read netCDF files and display variable information



03 May 2011 (Updated )

Loads netCDF files and displays info about variables. Tested for ERA and NCEP/NCAR reanalysis data.

| Watch this File

File Information

This script loads netCDF files into MATLAB and displays info about the dimensions and variables.

The code should at least work on ERA-40, ERA-interim and NCEP/NCAR reanalysis data.

I wrote the script since I can't find a function in the built-in set of netCDF functions included in MATLAB that displays all header info of the file, equivalent to the old 'ncdump' function.

MATLAB release MATLAB 7.10 (R2010a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (7)
26 Nov 2016 Arcues

Arcues (view profile)

23 Oct 2014 Francisco

Hi, I used your script, It worked perfect, except for the time variable. I don't understand the value, I tried with matlab date format, but It's not. Could you explain me? I'm using pressure levels from Era-Interim.

Comment only
01 Jul 2014 Christian Stranne


I can help you to plot the data if you describe the data set you are using and what kind of plot you want to make.

Send an email to

Comment only
30 Jun 2014 Ricardo

Can you help me how to plot it?

Comment only
26 Mar 2013 Christian Stranne


There is a link to the upper right of the web page "CS_read_netCDF.m". If you left click on the link you will see the code and you can copy/paste. You can also right click and choose "save link as" and save the file to your computer. Hope this helps.

/ Christian

Comment only
26 Mar 2013 Roberta Dag

This file does not exist... How / where can I find this script? Thank you... I work with NCEP/NCAR and I really need this.

Comment only
27 Jun 2012 nan

nan (view profile)

Thanks, this was very close to what I was looking for and worked as an example of using the low level NetCDF routines.

I wanted to pass the data back to a calling routine as a structure, and also wanted to remove the singleton dimensions, so I updated the getVar call to:
eval(['dstruct.' varname '= double(squeeze(netcdf.getVar(ncid,i)));']) ;

Since I also wanted to load the attributes into another structure, I needed to add some steps to handle attribute names that are not legal field names, converting spaces etc to underscores; also the assign statements for character attributes needed to be modified for that.

An excellent example file for the Matlab help would be a routine that loads a NetCDF file, modifies some fields, and writes out a new NetCDF. That would cover all the bases, I think. In the absence of that, this was a big help - thanks!

03 May 2011 1.1

Just added in the description the fact that the code is only tested on ERA-40, ERA-interim and NCEP/NCAR reanalysis data.

The first part (the load and display part) should work for any netCDF-file I would imagine.

17 May 2011 1.2

Bug fix

25 Feb 2013 1.5

Changed the info about the script

26 Aug 2013 1.8

Bug fix

Contact us