Fast interpolation

版本 1.0.0.0 (1.5 KB) 作者: Nathaniel Brahms
Performs nearest-neighbor or linear interpolation much faster than interp1 when an evenly-spaced lib
6.6K 次下载
更新时间 2006/4/18

无许可证

This function performs interpolation faster than MATLAB's "interp1" function. In the limit of small library and search arrays, it is ~5x faster. In the limit of large library arrays, qinterp1 has a flat scaling, while interp1 has a linearly increasing scaling (see the image for this file). qinterp1 requires an evenly spaced, monotonically increasing x array. Like interp1, qinterp1 returns NaN for xi values that are out of bounds.

Per John D'Errico's suggestion, the nearest-lower-neighbor method has been changed to now use true nearest-neighbor interpolation (at a slight speed cost).

A note on error checking: Because any error checking of the library array would destroy the flat scaling law, this function performs no error checking on the library (x and y) arrays. This function will return an error if the y and xi arrays are not both column or both row vectors.

Type "help qinterp1" for usage instructions.

This should be backwards compatible for quite a few releases. It is platform-independent.

The attached image shows the result of speed tests performed on a 2.4GHz, 2GB Windows XP machine. The same x, y, and xi vectors were used for each algorithm. The qinterp1 method came out ahead in all parameters tested. Note that, surprisingly, in the case of evenly-spaced x vectors, interp1q is slower than interp1 for most parameters, and interp1's nearest-neghbor interpolation is almost always slower than linear interpolation!

Note: After writing this function, I noticed Umberto Picchini's fast interpolation function, which provides up to a 4x speedup without the requirement of an evenly-spaced array. The file ID is 8627.

引用格式

Nathaniel Brahms (2024). Fast interpolation (https://www.mathworks.com/matlabcentral/fileexchange/10286-fast-interpolation), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R14SP3
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.0.0.0

Now returns NaN for any xi=NaN