How can I use different methods for interpolation and extrapolation in "retime" or "synchronize" functions in MATLAB R2022a?
조회 수: 10 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2022년 9월 22일
답변: MathWorks Support Team
2023년 1월 6일
I would like to use different methods for interpolation and extrapolation in "retime" or "synchronize", e.g. use linear interpolation and use nearest neighbor extrapolation at the same time. Currently, the extrapolation in these functions can only be done using the same method as specified for interpolation, or using a specified constant extrapolation value by means of the `EndValues` argument.
For example:
x = (1:10)+rand(1,10)-0.5;
tt = timetable(years(1:10)',x'); % Dummy timetable example
retimett = retime(tt,years(1:0.5:12),'linear'); % Linearly interpolates and extrapolates. Cannot use separate methods for each.
채택된 답변
MathWorks Support Team
2022년 9월 22일
This is a known limitation of these functions as of MATLAB R2022b. However, the development team is aware of this limitation and may consider addressing it in the future releases.You may work around it by calling "retime" or "synchronize" twice and combining the results using logical indexing.
For example, the following code demonstrates the use of linear interpolation and nearest-neighbor extrapolation:
x = (1:10)+rand(1,10)-0.5;
tt = timetable(years(1:10)',x'); % Dummy timetable example
retimett1 = retime(tt,years(1:0.5:12),'linear'); % Linearly interpolates and extrapolates
retimett2 = retime(tt,years(1:0.5:12),'nearest'); % Interpolates and extrapolates using nearest neighbor
extrapolateIdx = retimett1.Properties.RowTimes > tt.Properties.RowTimes(end); % Get indices for extrapolated points
retimett1(extrapolateIdx,:) = retimett2(extrapolateIdx,:); % Move the nearest neighbor extrapolation results to linear interpolation timetable
댓글 수: 0
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!