How to open multiple nc files
2 次查看(过去 30 天)
显示 更早的评论
Hi
I want to load data from 4 different .nc files (four months), but with the same structure and same variables. Can only read them one file at a time. How can I figure it out as a single data file?
How I load one file:
file='December81.nc'
file1='Januar82.nc'
file2='Februar82.nc'
file3='Marts82.nc'
%Viser indholdet af filen.
ncdisp(file)
ncdisp(file1)
ncdisp(file2)
%Åbner filen, så den kun kan læses
ncid=netcdf.open(file,'NOWRITE')
ncid1=netcdf.open(file1,'NOWRITE')
ncid2=netcdf.open(file2,'NOWRITE')
%Indlæser dimensioner, variabler, attributter, 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
%Definerer længdegrader, breddegrader, tid og z
lon = ncread(file,'longitude') ; nx = length(lon) ;
lat = ncread(file,'latitude') ; ny = length(lat) ;
time = ncread(file,'time') ; nt = length(time);
z = ncread(file,'z') ; nz = length(z);
3 个评论
Walter Roberson
2018-11-21
plot does not know or care where data comes from . Use as many files or functions as you need to construct the data to pass to plot.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NetCDF 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!