How to read netcdf files containing string arrays?
이전 댓글 표시
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:
ncread('string_test.nc','StringArray')
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 http://piotr.majdak.com/temp/netcdf/ where also more description is available.
I'm using Matlab 2011b - any ideas what I can do?
댓글 수: 1
Van Thuan
2025년 4월 29일
Just updating to Matlab2024b solved this problem in for me.
채택된 답변
추가 답변 (3개)
Peter Kuma
2018년 8월 20일
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
enhacement.
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
Workaround:
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
Anna Weeks
2018년 8월 21일
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.
Maxime Hervo
2017년 3월 31일
0 개 추천
Is there any update for this issue ? I still have the same problem with MATLAB R2016b !
liu jibao
2018년 1월 31일
0 개 추천
Is there any update for this issue ? I still have the same problem with MATLAB R2017b !
댓글 수: 4
N/A
2018년 3월 1일
It seems nobody bothered to report it as a bug, so it is not surprising nothing has changed.
Natalie Perlin
2019년 7월 24일
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.
chidi
2023년 1월 23일
I've tried using the h5read and hdf5read function but I'm not getting desired results
For ref. VX= h5read('d20220602.nc','.............../current velocity down')
Output comes out as [15532×1 single] . . .[15532×1 single]
The expected output are water current data and its 56x1 array
How can I resolve this issue
Thanks
Kris Fedorenko
2025년 10월 23일
Just to update this thread - MATLAB supports reading and writing "string" datatype in netCDF files starting in R2021b
카테고리
도움말 센터 및 File Exchange에서 NetCDF Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!