DGradient

版本 1.0.0.0 (12.5 KB) 作者: Jan
Gradient of arrays as fast C-Mex
2.6K 次下载
更新时间 2011/1/2

查看许可证

Gradient along a specified dimension

Y = DGradient(X, Dim, Spacing, Method)
INPUT:
X: Real DOUBLE array, any number of dimensions.
Spacing: Scalar or vector of the length SIZE(X, Dim).
Dim: Dimension to operate on.
Optional, default: 1st non-singelton dimension.
Method: String, order of the applied method for unevenly spaced X:
'1stOrder', faster centered differences as in Matlab's GRADIENT.
'2ndOrder', 2nd order accurate centered differences.
On the edges forward and backward difference are used.
Optional, default: '1stOrder'.

OUTPUT:
Y: Gradient of X, same size as X.

There are a lot of other derivation tools in the FEX. This function is faster (e.g. 25% faster than dqdt and 10 to 16 times faster than Matlab's GRADIENT), works with multi-dim arrays, on a specific dimension only, and can use a 2nd order method for unevenly spaced data.
For vectors or evenly spaced data no temporary memory is needed. Otherwise 1 or 3 temporary vectors of SIZE(X, Dim) are used for the 1st and 2nd order methods.

The C-Mex file must be compiled at first. Pre-compiled files for Win32 can be downloaded at: http://www.n-simon.de/mex
Run the unit-test function uTest_DGradient to check the integrity and measure speed.

Tested: Matlab 6.5, 7.7, 7.8, WinXP, 32bit
Compiler: LCC2.4/3.8, BCC5.5, OWC1.8, MSVC2008
Assumed Compatibility: higher Matlab versions, Mac, Linux, 64bit

Thanks to Robert A. Canfield (central_diff, #12) and Darren Rowland (diffxy, #29312).

引用格式

Jan (2024). DGradient (https://www.mathworks.com/matlabcentral/fileexchange/29887-dgradient), MATLAB Central File Exchange. 检索来源 .

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

Community Treasure Hunt

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

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