|MATLAB Function Reference|
The gradient of a function of two variables, , is defined as
and can be thought of as a collection of vectors pointing in the direction of increasing values of . In MATLAB, numerical gradients (differences) can be computed for functions with any number of variables. For a function of variables, ,
FX = gradient(F)
F is a vector returns the one-dimensional numerical gradient of
FX corresponds to , the differences in the direction.
[FX,FY] = gradient(F)
F is a matrix returns the and components of the two-dimensional numerical gradient.
FX corresponds to , the differences in the (column) direction.
FY corresponds to , the differences in the (row) direction. The spacing between points in each direction is assumed to be one.
[FX,FY,FZ,...] = gradient(F)
N dimensions returns the
N components of the gradient of
F. There are two ways to control the spacing between values in
h, specifies the spacing between points in every direction.
Nspacing values (
h1,h2,...) specifies the spacing for each dimension of
F. Scalar spacing parameters specify a constant spacing for each dimension. Vector parameters specify the coordinates of the values along corresponding dimensions of
F. In this case, the length of the vector must match the size of the corresponding dimension.
[...] = gradient(F,h)
h is a scalar uses
h as the spacing between points in each direction.
[...] = gradient(F,h1,h2,...)
N spacing parameters specifies the spacing for each dimension of