How to do 'previous' interp1 behavior in 2014a?

Hello,
I used interp1 in 2015b recently, and made use of the 'previous' interpolation function which will just return the YY value of the previous XX point. In 2014a however, when run using 'previous', if you actually look at the code it runs using 'pchip' instead as it only matches on the first letter! It seems that 'previous' is missing from earlier MATLAB versions.
interp1(X,Y,XX,'previous') is fast enough for my application, although I now need to use it in 2014a where it seems to be unavailable. Can anybody suggest a fast alternative algorithm? Any solution I have come up with seems horrendously slow compared to interp1.
Thanks!

1 件のコメント

Steven Lord
Steven Lord 2016 年 4 月 20 日
FYI the 'previous' and 'next' options for interp1 were introduced in release R2014b, as indicated in the third item in the Mathematics section of the Release Notes for that release.

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2016 年 4 月 20 日

0 投票

Two output version of histc(), use the resulting bin numbers to index the edge list, and that will correspond to "previous".

3 件のコメント

Oliver Hawker
Oliver Hawker 2016 年 4 月 20 日
I'm not sure I understand, could you give me a super-quick example in terms of X, Y and XX?
Thanks for your help
Walter Roberson
Walter Roberson 2016 年 4 月 20 日
Assuming that X is in strictly ascending order,
[counts, binnumbers] = histc(XX, X);
y_at_x_no_later = Y(binnumbers);
Oliver Hawker
Oliver Hawker 2016 年 4 月 20 日
That's great, I never would have thought of doing it that way, thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by