Can I use a nearest neighbor extrapolation strategy with interp1?

58 ビュー (過去 30 日間)
Matthew Casiano
Matthew Casiano 2022 年 8 月 4 日
編集済み: Matt J 2022 年 8 月 5 日
Is there a way that interp1 can be set up to use a nearest neighbor extrapolation approach (while also using an alternate interpolation appraoch)? In other words, values that come prior to the start of a vector use the first value from that vector, and values that come after the end of a vector use the last value from that vector.
The only options appear to be 'extrap' which uses the interpolation method, and a specification of a value. Maybe there is a clever way to specify a condition here that would return a value for the start or end of the vector?

採用された回答

Matt J
Matt J 2022 年 8 月 4 日
編集済み: Matt J 2022 年 8 月 5 日
If you want to mix interpolation and extrapolation methods, use griddedInterpolant instead:
F=griddedInterpolant(1:5,'linear','nearest');
F(xq)
ans = 1×3
1.0000 2.5000 5.0000

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by