How to open multiple nc files

1 Ansicht (letzte 30 Tage)
Jonas Damsbo
Jonas Damsbo am 21 Nov. 2018
Kommentiert: Walter Roberson am 21 Nov. 2018
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 Kommentare
Jonas Damsbo
Jonas Damsbo am 21 Nov. 2018
Bearbeitet: Jonas Damsbo am 21 Nov. 2018
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 am 21 Nov. 2018
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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by