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!