Datetime in a loop that concatenates NetCDF

1 Ansicht (letzte 30 Tage)
Tim Holgate
Tim Holgate am 10 Dez. 2020
Beantwortet: Eric Sofen am 11 Dez. 2020
Hi,
I've written a concatnation loop that is supposed to make an array of NetCDF files. This is the code that I have:
time_all=(Nfiles);
sss_all=zeros(Nfiles, length(lon1), length(lat1));
for i = 1:Nfiles
ncfiles(i).name %this just helps my OCD in listing the name of the file
time1 = ncread(ncfiles(i).name, 'time');
time= datetime(1950,1,1)+days(time1);
sss = ncread(ncfiles(i).name, 'SSS');
%concatdat= cell(lat,lon,sss)
sss_all(Nfiles, :, :) = sss;
time(Nfiles)=time;
end
It concatenates fine; however the 'time= datetime(1950,1,1)+days(time1);' function does not seem to function. It corrects the first files date from days since 01 01 1951 but then fills the rest of the dates with NaT. Any ideas what I am doing wrong?

Antworten (1)

Eric Sofen
Eric Sofen am 11 Dez. 2020
The last line of your loop:
time(Nfiles)=time;
should be
time_all(Nfiles)=time;
so that you update time_all.
Beyond that, check what time1 is in subsequent loop iterations and make sure that it is numeric so it can be converted to days. I don't see anything wrong with the datetime calculation.

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by