MATLAB Function Reference    
gradient

Numerical gradient

Syntax

Definition

The gradient of a function of two variables, F(x,y), 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 N variables, F(x,y,z,...),

Description

FX = gradient(F) where F is a vector returns the one-dimensional numerical gradient of F. FX corresponds to , the differences in the x direction.

[FX,FY] = gradient(F) where F is a matrix returns the x and y components of the two-dimensional numerical gradient. FX corresponds to , the differences in the x (column) direction. FY corresponds to , the differences in the y (row) direction. The spacing between points in each direction is assumed to be one.

[FX,FY,FZ,...] = gradient(F) where F has N dimensions returns the N components of the gradient of F. There are two ways to control the spacing between values in F:

[...] = gradient(F,h) where h is a scalar uses h as the spacing between points in each direction.

[...] = gradient(F,h1,h2,...) with N spacing parameters specifies the spacing for each dimension of F.

Examples

The statements

produce

Given,

See Also

del2, diff


 gplot graymon