File Exchange

image thumbnail

NetCDF reader

version (2.65 KB) by Paul Spencer
Reads NetCDF files into matlab structure


Updated 05 Jun 2007

View License

Function to read version 1 (classic 32bit) NetCDF files into a matlab structure.

Cite As

Paul Spencer (2020). NetCDF reader (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (34)

Cong Qiu

Mark Wright

nowdays there are toolboxes that make nc file very hand-able.
but if you use an older version of matlab (before 2011) this script is a very good option.

but i am using a 2009 matlab, and it keeps turning my data to int16 loosing all the info in the decimals (my scripts in newer version using ncinfo and ncread works correctly)

I have no idea how to treat this bug

This contribution is good as it does not depend on any other library.

good job thanks


does Matlab reads also .ncs file?

Thank you very much for this code it seems work but I can't use struct file on matlab Could you please help me to extract the variables from S


Brian Emery

Thanks for this. In our group, a few people have the newer 2010 version of Matlab with a built in netCDF library. This is good for one of my machines that does not have it. A few tweaks to my own codes here and there to use it but it works nicely. I am using it under SUSE.


I tried to extract COSMIC ionPrf file runing netcdf.m . It reads only the header information (NumRecs: 0). I need to read data records. Can any one tell me how to read data?


I am using netcdf.m file with .nc format but I got this error:
Error using ==> reshape
To RESHAPE the number of elements must not change.
The outcome contains only 2 out of 3 matrix.
What should I do to resolve the error?


I've downloaded netcdf.m file. In which folder I have to put it?I use Matlab 7.7 r2008b. Please help me! Thanks

Pavel ?

excellent work!

visualize netcdf

Excellent submission. Note that unsigned integer variables (uint8) seem to be loaded as signed integers (int8). I use the typecast function to correct that. I haven't checked for any other bugs. Thanks for this really useful function!

I haven't used it heavily yet so there may still be issues -- but it appears that this script works just fine for Matlab in Linux. (Ubuntu/Debian). It really ought to -- NETCDF is supposed to be platform agnostic.

??? Error using ==> feval
Undefined function or method 'mexcdf60' for input arguments of type 'char'.

What should I do to resolve the above error?
I am totally new to this type of data and mex-files. Please, help.

roc light

Jian Xu

I really need this function, I hope it's helpful..

William Amidon

works beautifully. Thank you so much. This is a great help for us matlab users trying to work with large climate datasets.

Niranjan kumar

I am extreamly thank you


Usama Anber

great, but how to visualize climate data on a map ?

Patrizio M


D Luna

Great! Fantastic!

w s

Thanks a lot. Exactly what I needed.

ali altalhy

Ibrahim Modibbo

Wow! I cant believe it...even people's comments until i saved this file into my working dir and used it in place of load on matlab file is there!
Thats a great job!

Will it be possible for you to extend this for ARGO data, and possibly how to make some few plots? This would have added extreme help to many people! Pls reply me....

I am PhD student at National Oceanography Centre, Southampton, UK.

Hope to hear from you!


Liam Harrington-Missin

Very Easy to use and quick, at least for smaller NetCDF files

Patrick Gagnon

It's by far the simplest way that I found to read netcdf data in Matlab R14.



Kelly Kearney

This is a nice complement to some of the more powerful netcdf libraries available. Becuase it reads in an entire file at once, it can only deal with small .nc files, but is much less hassle than the mexnc library I usually use. However, it would be nice if it did some checks ahead of time to see if the file it's reading is too big to be read into Matlab all at once (based on the header data), and errored out immediately, rather trying to do the impossible.


Updated to allow for the reading of selected data arrays and records

MATLAB Release Compatibility
Created with R14
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired: Read Global Topographic Data