Interpolate timeseries of a 4D matrix (4th D as time)
조회 수: 55 (최근 30일)
이전 댓글 표시
Luís Henrique Bordin
2024년 11월 6일 16:48
댓글: Luís Henrique Bordin
2024년 11월 6일 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
채택된 답변
Stephen23
2024년 11월 6일 17:10
편집: Stephen23
2024년 11월 6일 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)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Time Series Events에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!