problems writing netcdf file with 3-d variable
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello,
I am trying to write some data I have to a netcdf file. Here is the code:
st_num = 1:370;
year = 1895:2011;
month = 1:12;
% Open netCDF file.
ncid = netcdf.create('SPEI1.nc','NC_WRITE');
% Define the dimensions of the variable.
IDdimid = netcdf.defDim(ncid,'station_ID',length(st_num));
modimid = netcdf.defDim(ncid,'month',length(month));
yeardimid = netcdf.defDim(ncid,'year',length(year));
data_ids = ([IDdimid modimid yeardimid]);
data_ids
whos
yearID = netcdf.defVar(ncid,'year','double',yeardimid);
moID = netcdf.defVar(ncid,'month','double',modimid);
stnumID = netcdf.defVar(ncid,'station_ID','double',IDdimid);
dataID = netcdf.defVar(ncid,'SPEI1','double',data_ids);
% Leave define mode and enter data mode to write data.
netcdf.endDef(ncid)
% Write data to variable.
netcdf.putVar(ncid,dataID,SPEI1);
netcdf.close(ncid);
My SPEI1 variable is a 117x12x370 double. The data that is written into SPEI1 is not in the correct location and much of the newly written data does not exist in my original SPEI1 Matlab variable.
When I dump the netcdf file all the dimensions seem to be as they should though...:
NetCDF SPEI1.nc {
dimensions:
station_ID = 370 ;
month = 12 ;
year = 117 ;
variables:
// Preference 'PRESERVE_FVD': false,
// dimensions consistent with ncBrowse, not with native MATLAB netcdf package.
double year(year), shape = [117]
double month(month), shape = [12]
double station_ID(station_ID), shape = [370]
double SPEI1(year,month,station_ID), shape = [117 12 370]
Do anyone have any suggestions for my problem?
Thanks, Dan
댓글 수: 4
Ashish Uthama
2011년 11월 8일
Dan, if data_ids = ([IDdimid modimid yeardimid]); i.e the variable dimensions ought to match the order of the defined dimensions (370x12x117).
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 NetCDF에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!