Datetime in a loop that concatenates NetCDF

조회 수: 1 (최근 30일)
Tim Holgate
Tim Holgate 2020년 12월 10일
답변: Eric Sofen 2020년 12월 11일
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?

답변 (1개)

Eric Sofen
Eric Sofen 2020년 12월 11일
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.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by