Need help with Ncwrite
2 次查看(过去 30 天)
显示 更早的评论
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.
采纳的回答
Ashish Uthama
2012-10-16
编辑:Ashish Uthama
2012-10-16
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
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!