Function Reference
— Function File: x = gradient (M)
— Function File: [x, y, ...] = gradient (M)
— Function File: [...] = gradient (M, s)
— Function File: [...] = gradient (M, dx, dy, ...)

Calculates the gradient. x = gradient (M) calculates the one dimensional gradient if M is a vector. If M is a matrix the gradient is calculated for each row.

[x, y] = gradient (M) calculates the one dimensional gradient for each direction if M if M is a matrix. Additional return arguments can be use for multi-dimensional matrices.

Spacing values between two points can be provided by the dx, dy or h parameters. If h is supplied it is assumed to be the spacing in all directions. Otherwise, separate values of the spacing can be supplied by the dx, etc variables. A scalar value specifies an equidistant spacing, while a vector value can be used to specify a variable spacing. The length must match their respective dimension of M.

At boundary points a linear extrapolation is applied. Interior points are calculated with the first approximation of the numerical gradient

          y'(i) = 1/(x(i+1)-x(i-1)) *(y(i-1)-y(i+1)).