Why does ncread misreads a string variable?

5 views (last 30 days)
Hello
I am reading data from a netcdf file using ncread. All is well, except when trying to read a particular string variable, containing multiple lines of text. I have read the variable data using ncks, which I include with (part of) the output below (1). Reading it in matlab does not produce an error message but returns a string of seemingly random characters, part of which is copied below (2). Any idea why this may be?
Thanks,
Aviv
p.s.
The netcdf file type is 'classic' mas inquired by "ncdump -k (filename)"
_______________________________________________
(1) Reading the variable with ncks from the command line
ncks -H -v LAUNCH_CONFIG_PARAMETER_NAME 1900037_meta.nc
netcdf 1900037_meta {
dimensions:
N_LAUNCH_CONFIG_PARAM = 9 ;
STRING128 = 128 ;
variables:
char LAUNCH_CONFIG_PARAMETER_NAME(N_LAUNCH_CONFIG_PARAM,STRING128) ;
data:
LAUNCH_CONFIG_PARAMETER_NAME =
"CONFIG_ParkAndProfileCycleCounter_COUNT ",
"CONFIG_CycleTime_hours ",
"CONFIG_DescentToParkTimeOut_hours ",
______________________________________________________
(2) reading the variable using ncread in matlab
K>> LaunchParamNames = ncread(1900037_meta.nc, 'LAUNCH_CONFIG_PARAMETER_NAME')
LaunchParamNames =
128×9 char array
'CCCCCCCCC'
'OOOOOOOOO'
'NNNNNNNNN'
'FFFFFFFFF'
'IIIIIIIII'
'GGGGGGGGG'
'_________'
'PCDPASTPP'
'ayeasurar'
'rcsrcraro'
'klckefnkf'
'AeeTnasPi'
'nTnitcmrl'
'ditmTeiee'
'PmTeoTssP'
'reo_Sissr'
'o_Phumiue'
'fhaoreors'
'iorufOnes'
'lukrauR_u'
'erTsctedr'
'Csi e_pbe'
'y m Thea_'
'c e iotrd'
'l O mui b'
'e u ert a'
'C t Osi r'
'o _ u o '
'u h t n '
'n o _ P '
't u h e '
'e r o r '
'r s u i '

Accepted Answer

Walter Roberson
Walter Roberson on 12 Apr 2019
You do not have strings. You have a char array. Like all matlab arrays it is stored in MATLAB in column major order, so A(2,1) is what is adjacent to A(1,1). netcdf stores in row major order not column major order. Every time you read in a 2D array from netcdf you may need to transpose it.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!