LERP: fast n-dimensional linear interpolation & extrapolation

版本 1.5.0.0 (2.6 KB) 作者: Sky Sartorius
Interpolate from X and Y data and n-dim array. Can also extrapolate above/below X if desired.
1.4K 次下载
更新时间 2012/11/27

查看许可证

Syntax:
F=LERP(X,Y,XI)
F=LERP(X,Y,XI,EXTRAP)

LERP is akin to the Matlab function INTERP1Q and can be used with the same syntax as INTERP1Q with the same results at comparable speed. However, LERP has the following features and capabilities to set it apart from INTERP1Q and others:
•Vectorization allows LERP to be much faster that built-in MATLAB interpolation functions for some applications that would otherwise require many looped function calls.
•XI may be an n-dim array
•Y may be a column vector or a matrix (as in INTERP1Q)
•If Y is a matrix and XI is an array with N dimensions, F will have N+1 dimensions. The first N dimensions correspond to size(XI), and the N+1 dimension is size(Y,2).
•F=LERP(X,Y,XI,EXTRAP) will expand the function domain (defined in coordinates X) with linear extrapolation by a distance EXTRAP in either direction. EXTRAP may also be a 2-element vector with the first element defining the extrapolation distance below the beginning of X and the second element defining the extrapolation distance beyond the final value of X.

LERP has similar limitations to INTERP1Q

Example: interpolation for log and log10 functions with plot comparing extrapolation to reality
X = (linspace(.01, 2, 7)').^2;
Y = [log(X) log10(X)];
XI = magic(7)*.2 - .5;
F = lerp(X, Y, XI, [0 4])
x = linspace(4,8);
plot(X,Y,x,log(x),'r:',x,log10(x),'r:',XI,F(:,:,1),'bo',XI,F(:,:,2),'ko')

引用格式

Sky Sartorius (2025). LERP: fast n-dimensional linear interpolation & extrapolation (https://www.mathworks.com/matlabcentral/fileexchange/28432-lerp-fast-n-dimensional-linear-interpolation-extrapolation), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R2007b
兼容任何版本
平台兼容性
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.5.0.0

couple of logic and coding fixes; some edits to help and example

1.0.0.0