Interpolate timeseries of a 4D matrix (4th D as time)
55 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Luís Henrique Bordin
am 6 Nov. 2024 um 16:48
Kommentiert: Luís Henrique Bordin
am 6 Nov. 2024 um 18:41
Hey experts, please could you help me to figure this out?
I am trying to interpolate a 4D matrix, in which the 4th dimension is time. It has 12 records (monthly), but I want it each 3 days, so it'll be 121 records).
For this I am trying both ways below:
load data.mat
dtStr = ["15/01/2016","15/02/2016","15/03/2016","15/04/2016","15/05/2016","15/06/2016",...
"15/07/2016","15/08/2016","15/09/2016","15/10/2016","15/11/2016","15/12/2016"];
dtvA=datevec(dtStr,'dd/mm/yyyy');
dttA = datetime(dtvA);
timeS = datestr((time/86400)+datenum(1958,1,1));
dttB = datetime(timeS);
tmtb = timetable(dttA,Nit2);
NO3_clim_3daily = retime(tmtb,'regular','linear','TimeStep',days(3));
% Or
NO3_clim_3daily = retime(tmtb,dttB,'linear');
But it give me the error: "Error using timetable/retime (line 140). Interpolation requires at least two sample points in each dimension".
Why am I getting this error, if I have a matrix of 31x11x37x12?
I still could not figure it out and how to solve it. Please, could someone help me?
Thanks!
0 Kommentare
Akzeptierte Antwort
Stephen23
am 6 Nov. 2024 um 17:10
Bearbeitet: Stephen23
am 6 Nov. 2024 um 17:21
Avoid using deprecated DATENUM & DATESTR, using DATETIME is much better.
S = load('data.mat')
dttA = datetime(2016,1:12,15);
dttB = datetime(S.time(:),'convertfrom','epochtime','Epoch',datetime(1958,1,1));
"Why am I getting this error, if I have a matrix of 31x11x37x12?"
Note that for a TIMETABLE the first dimension (i.e. rows) must correspond to the time: in contrast the 4th dimension of your array has size 12, thus seems to correspond to the 12 months you specified. So we would need to permute that array so that it fits the TIMETABLE definition:
tmtb = timetable(dttA(:),permute(S.Nit2,[4,1,2,3]))
after that RETIME is exactly as you showed:
NO3_clim_3daily = retime(tmtb,'regular','linear','TimeStep',days(3))
NO3_clim_3daily = retime(tmtb,dttB)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Time Series Events finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!