Info

This question is closed. Reopen it to edit or answer.

How to read more than one netcdf file?

1 view (last 30 days)
Jonas Damsbo
Jonas Damsbo on 21 Nov 2018
Closed: MATLAB Answer Bot on 20 Aug 2021
I got around 480 netcdf-files that needs to be run in the same matlab-script. The files are named in a logical format, like this:
January79, February79, Marts79, April79, May79, June79, July79, August79, September79, October79, November79, December79, January80 and so on.
To open one file I do this:
filename='December81.nc'
%Shows the contents of the file
ncdisp(filename)
%Open in read mode
ncid=netcdf.open(filename,'NOWRITE')
%Loads dimensions, variables, attributtes, unim
[ndim, nvar, natt, unlim]=netcdf.inq(ncid)
for i=0:nvar-1
[varname, xtype, dimid, natt]=netcdf.inqVar(ncid,i);
if strcmp(varname,'surf_temp')==1
varnumber=i;
end
end
for i=1:length(dimid)
[dimname, dimlength]=netcdf.inqDim(ncid,dimid(1,i))
end
for i=0:nvar-1
[varname, xtype, dimid, natt]=netcdf.inqVar(ncid,i);
if strcmp(varname,'latitude')==1
dimnumber=i
end
end
%Defines logitudes, latitudes, time og z
lon = ncread(filename,'longitude') ; nx = length(lon) ;
lat = ncread(filename,'latitude') ; ny = length(lat) ;
time = ncread(filename,'time') ; nt = length(time);
z = ncread(filename,'z') ; nz = length(z)
So my question is, how do I open more files, such as December81, January82 and February82 so I can use these data from this months in one script?

Answers (0)

Community Treasure Hunt

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

Start Hunting!