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)
Afficher commentaires plus anciens
MathWorks Support Team
le 22 Sep 2022
Réponse apportée : MathWorks Support Team
le 6 Jan 2023
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
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
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Interpolation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!