Reading multiple netcdf files and then produce a single Matlab matrix

2 views (last 30 days)
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

Answers (0)

Community Treasure Hunt

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

Start Hunting!