Datetime in a loop that concatenates NetCDF
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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?
0 Commenti
Risposte (1)
Eric Sofen
il 11 Dic 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.
0 Commenti
Vedere anche
Categorie
Scopri di più su NetCDF in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!