Need help with Ncwrite

2 visualizzazioni (ultimi 30 giorni)
Al Onen
Al Onen il 15 Ott 2012
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.

Risposta accettata

Ashish Uthama
Ashish Uthama il 16 Ott 2012
Modificato: Ashish Uthama il 16 Ott 2012
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 Commenti
Al Onen
Al Onen il 19 Ott 2012
Sorry I was busy with a conference, I will check it tomorrow :)
Al Onen
Al Onen il 21 Ott 2012
With some modification, it finally worked. Thank you :)

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by