필터 지우기
필터 지우기

How to save character matrix into NetCdf files?

조회 수: 8 (최근 30일)
Vijay Sagar
Vijay Sagar 2022년 8월 3일
댓글: Vijay Sagar 2022년 8월 4일
Hi everyone, I have character matrix A1
A1='101670 '
'101670 '
'101670 '
'101670 '
'101670 '
'101670 '
'101670 '
'101670 '
'101670 '
'101670 '
'101670 '
'101670 '
'101670 '
I am trying to save it into a netcdf file using ncreate and ncwrite.
nccreate('file_name.nc','A1',...
'Dimensions', {'x',size(A1,1),'y',size(A1,2)},...
'FillValue','disable');
ncwrite(file_name,'A1',A1);
But It is showing some error releted to conversion of between text and number.
Error using netcdflib
The NetCDF library encountered an error during execution of 'putVaraText' function -
'Attempt to convert between text & numbers (NC_ECHAR)'.
Error in netcdf.putVar (line 84)
netcdflib(funcstr,ncid,varid,varargin{:});
Error in internal.matlab.imagesci.nc/write (line 844)
netcdf.putVar(gid, varid,start, count, varData);
Error in ncwrite (line 75)
ncObj.write(varName, varData, start, stride);
Can someone help me how to save the character matrix into netcdf file?

채택된 답변

Walter Roberson
Walter Roberson 2022년 8월 3일
The default data type is double. You need the "datatype" option.
Please recheck what x and y mean to you. You are using x as height of the matrix, but by convention y is height.
  댓글 수: 1
Vijay Sagar
Vijay Sagar 2022년 8월 4일
Thank you Walter Roberson for kind response. It helped me. I have just includes datatype option, then it worked. As per the requirement, I interchange the 'x' and 'y' options, so there is issue here.
nccreate('file_name.nc','A1',...
'Dimensions', {'x',size(A1,1),'y',size(A1,2)},...
'FillValue','disable','Datatype','char');
ncwrite('file_name.nc','A1',A1);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 NetCDF에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by