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개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!