"Error: using netcdflib 'dimids' should be double precision" when trying to create variable in NetCDF file

조회 수: 4 (최근 30일)
I'm trying to create a NetCDF file of some timeseries data. I've successfully defined the dimensions and global attributes for my data, but when I try to write my first variable, I get: Error using netcdflib 'dimids' should be double precision.
This is the code I have written to create the variable, and it's the third line that produces the error:
netcdf.reDef(ncid);
nccreate('TVC_Jan2018.nc','Shortwave');
varid = netcdf.defVar(ncid,'Shortwave','double',['lon',1,'lat',1,'time',744]);
nccreate(ncid,varid,'Dimensions',{'lon',1,'lat',1,'time',sz},'Format','classic','Datatype','double');
netcdf.putAtt(ncid,varid,'long_name','Incoming Shortwave Raditation');
netcdf.putAtt(ncid,varid,'units','W m^–2');
netcdf.putAtt(ncid,varid,'mode','time varient');
for t = 1:sz
ncwrite('TVC_Jan2018.nc','Shortwave',MetData_Jan(t,5));
end
netcdf.endDef(ncid);
I've googled and the default precision for numbers in Matlab should be double, so I have no idea where this error is coming from.
  댓글 수: 2
Nitish Nalan
Nitish Nalan 2020년 8월 28일
Hi Victoria,
Could you please try the script mentioned below, and let me know if this helps you.
clc
clear
lon = 1;
lat = 1;
time = 744
mcid = netcdf.create('Example_test.nc','NC_WRITE');
dimLon = netcdf.defDim(mcid,'lon',lon);
dimLat = netcdf.defDim(mcid,'lat',lat);
dimTime = netcdf.defDim(mcid,'time',time);
varid = netcdf.defVar(mcid,'Shortwave','NC_DOUBLE',[dimLon dimLat dimTime]);
netcdf.endDef(mcid);
ncdisp('Example_test.nc');
Victoria Dutch
Victoria Dutch 2020년 12월 7일
Sorry for taking an age to reply - that code does work. How would I then fill "Shortwave" with the information I want it to contain?
I thought I'd managed to fix this, but what I had created was a 744x1x1 nc file, rather than 1x1x744, so the model I need to use it in is not a fan.

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

답변 (0개)

카테고리

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

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by