How can I use different methods for interpolation and extrapolation in "retime" or "synchronize" functions in MATLAB R2022a?

8 vues (au cours des 30 derniers jours)
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.

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 22 Sep 2022
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

Plus de réponses (0)

Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by