Reading multiple netcdf files and then produce a single Matlab matrix

조회 수: 3 (최근 30일)
Christina
Christina 2013년 5월 23일
Hello,
I've got various netcdf file, in total 1000. In order to make things easier, I'm working with 3 of them at the moment.
The netcdf files are located in a folder called 'OUTPUT' and are called 'output1.SOILA.01h.nc', 'output2.SOILA.01h.nc' and so on..
What I want to do is to loop over those nc files open them, read them and finally store the outputs in a single matlab matrix.
The code I used until now in order to read a single netcdf file is below, but how do i handle 1000 of them?
function data = ReadNetCDF_SA
fn='./OUTPUT/output1.SOILA.01h.nc';
ncid = netcdf.open(fn,'NC_NOWRITE');
[ndims nvars natts dimm] = netcdf.inq(ncid);
data.filename=fn;
for i=1:nvars
[varname, xtype, varDimIDs, varAtts] = netcdf.inqVar(ncid,i-1);
disp(varname);
varid = netcdf.inqVarID(ncid,varname);
data=setfield(data,varname,netcdf.getVar(ncid,varid));
end
netcdf.close(ncid);
end
Thanks a lot,
Christina

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