필터 지우기
필터 지우기

Need help with Ncwrite

조회 수: 4 (최근 30일)
Al Onen
Al Onen 2012년 10월 15일
Hello, I have to transform a 63x132 (r,c) matrix from excel into a netcdf file, and wrote the following code,
year='2009';
month='07';
day={'12'; '13'; '14'; '15'; '16'; '17'};
hour={'00'; '01'; '02'; '03'; '04'; '05'; '06'; '07'; '08'; '09'; '10'; '11'; '12'; '13'; '14'; '15'; '16'; '17'; '18'; '19'; '20'; '21'; '22'; '23'};
for i = 1:6
for j = 1:24
Sheetname = strcat(year,month,day{i},hour{j},'00');
RAIN = xlsread('result2.xls',Sheetname);
NetCdfName=strcat(year,month,day{i},hour{j},'.MPE.nc');
nccreate(NetCdfName,'RAINNC', 'Dimensions', {'time', 1, 'south_north', 63, 'west_east', 132}, 'Format', 'classic');
ncwrite(NetCdfName,'RAINNC',RAIN, eye(63,132));
end
end
And I got the following error;
Error using netcdflib
Index argument is out of bounds.
Error in netcdf.putVar (line 87)
netcdflib(funcstr,ncid,varid,varargin{:});
Error in internal.matlab.imagesci.nc/write (line 819)
netcdf.putVar(gid,varid, start, count, varData);
Error in ncwrite (line 76)
ncObj.write(varName, varData, start, stride);
Error in ex2cdf (line 17)
ncwrite(NetCdfName,'RAINNC',RAIN, eye(63,132));
I couldn't find enough examples with nc functions, and tried to make my way with basic examples on documentation, but failed as you can see. Any help is much appreciated to create the file.
Thanks in advance.
  댓글 수: 1
Al Onen
Al Onen 2012년 10월 16일
Still waiting for guidance.

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

채택된 답변

Ashish Uthama
Ashish Uthama 2012년 10월 16일
편집: Ashish Uthama 2012년 10월 16일
The second example of ncwrite could be of some help.
Note that your call to NCWRITE is trying to use eye(63,132) as the START location (which is incorrect).
Maybe this example helps you get started:
NetCdfName = 't.nc';
nccreate(NetCdfName,'RAINNC', 'Dimensions', {'time', 10, 'south_north', 63, 'west_east', 132}, 'Format', 'classic');
ncdisp(NetCdfName);
for tInd = 1:10
RAIN = ones(63,132)*tInd; % Dummy data, based on what you mentioned your sheet contains
RAIN = reshape(RAIN,[1 63 132]); % We created a 3D data, so we need to provide a 3D data slice
ncwrite(NetCdfName,'RAINNC',RAIN,[tInd 1 1]);
end
%%verify
for tInd = 1:10
entry = ncread(NetCdfName,'RAINNC',[tInd 1 1],[1 1 1]);
disp(entry);
end
  댓글 수: 3
Al Onen
Al Onen 2012년 10월 19일
Sorry I was busy with a conference, I will check it tomorrow :)
Al Onen
Al Onen 2012년 10월 21일
With some modification, it finally worked. Thank you :)

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

추가 답변 (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