How to read netcdf files containing string arrays?

33 views (last 30 days)
I have a netCDF file which consists of a float array and a string array as verified by ncdump. In Matlab, I am able to load the float array, but I fail in loading the string array.
In particular, ncread produces an error:
Error using netcdf.getVar (line 130)
12 is not a recognized netCDF datatype.
"12" is the code for NC_STRING and it seems like Matlab can not handle that.
The .nc file I'm trying to load can be downloaded from where also more description is available.
I'm using Matlab 2011b - any ideas what I can do?

Accepted Answer

per isakson
per isakson on 5 Mar 2013
Edited: per isakson on 5 Mar 2013
I use R2012a.
ncdisp says: Datatype: UNSUPPORTED DATATYPE. See below. Why not accept that? What is the source of
HDFView 2.9 reads as if it was an HDF5-file. So does Matlab's h5disp and h5read.
>> ncdisp( '')
test = 4
Size: 4x1
Dimensions: test
Datatype: single
Size: 4x1
Dimensions: test
>> str = h5read( 'h:\m\cssm\', '/StringArray' )
str =
>> h5disp( 'h:\m\cssm\', '/StringArray' )
Dataset 'StringArray'
Size: 4
MaxSize: 4
Datatype: H5T_STRING
String Length: variable
Character Set: H5T_CSET_ASCII
Character Type: H5T_C_S1
ChunkSize: []
Filters: none
Piotr Majdak
Piotr Majdak on 6 Mar 2013
I'm slowly coming to a similar conclusion. Thanks for the help.

Sign in to comment.

More Answers (3)

Peter Kuma
Peter Kuma on 20 Aug 2018
Just to let others know, I have submitted a new bug report (since I could not find the one submitted by Erik). The answer was:
As you correctly pointed out, this is a current limitation of the
netCDF implementation. It is being actively investigated for
The workaround is to utilize the fact that netCDF4 formats are a
subset of the HDF5 format and we can utilize the HDF5 functionality
to read the data
Instead of ncdisp, ncread utilize h5disp, h5read
I hope the above workaround solves your issue. If you have any
further queries, please reach out to me.
  1 Comment
Anna Weeks
Anna Weeks on 21 Aug 2018
The ability to write a mapped array section of values into a netCDF variable (i.e the 'NF_PUT_VARM_ type' functionality) would be highly desirable.

Sign in to comment.

Maxime Hervo
Maxime Hervo on 31 Mar 2017
Is there any update for this issue ? I still have the same problem with MATLAB R2016b !

liu jibao
liu jibao on 31 Jan 2018
Is there any update for this issue ? I still have the same problem with MATLAB R2017b !
Natalie Perlin
Natalie Perlin on 24 Jul 2019
Thank you for filing the report, I wonder if anything has been done since then!
I have the same problem with Matlab not being able to read string variables in R2017a, R2018b.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!