How to open multiple nc files

조회 수: 2 (최근 30일)
Jonas Damsbo
Jonas Damsbo 2018년 11월 21일
댓글: Walter Roberson 2018년 11월 21일
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
Jonas Damsbo
Jonas Damsbo 2018년 11월 21일
편집: Jonas Damsbo 2018년 11월 21일
What I mean is that when I working with the data, I would like, for example. could plot them together in one plot - not 4 plots in one plot - I dont think i can do this with 4 separate files?
Walter Roberson
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 CenterFile Exchange에서 NetCDF에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by