Data not written correctly to netcdf file
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello,
I am trying to create a netcdf file with variables 'latitude', 'longitude' and 'zeros' to create a map of the world. I want to create a 0.5 degree grid so my latitude and longitude vectors have lengths of 360 and 720, respectively. My code (below) runs fine but when it creates the variable 'zeros' it does not write any data (i.e. has a cell value of 9.9692100e+36) for rows 714 (columns 246-360) and 715-720 (all columns). This produces a stripe going across my map when I visualise the data. Do you have any idea why this might be happening?
ncid = netcdf.create('Annual.nc','NC_NOCLOBBER');
%Define dimensions
londimid = netcdf.defDim(ncid,'lon', 720);
latdimid = netcdf.defDim(ncid,'lat', 360);
%Define variables
latvarid=netcdf.defVar(ncid, 'lat', 'float', latdimid);
lonvarid=netcdf.defVar(ncid, 'lon', 'float', londimid);
zerosvarid=netcdf.defVar(ncid, 'zeros', 'float', [latdimid londimid]);
netcdf.endDef(ncid)
%Write data to variables
netcdf.putVar(ncid,lonvarid,longitude);
netcdf.putVar(ncid,latvarid,latitude);
netcdf.putVar(ncid, zerosvarid, zeros(360,720));
댓글 수: 0
채택된 답변
Ashish Uthama
2011년 10월 7일
Anna, the data might not get fully written unless you close the file. A call to close would flush out all the data to the file:
netcdf.close(ncid);
Of course, you would then have to use netcdf.open to open the file again for reading.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!