[Nx,Ny,Nz] = surfnorm(___)
returns the components of the 3-D surface normals for the surface
without plotting the surface or surface normals.

Input Arguments

Z

2–D array of real numbers representing a surface

X

2–D array of real numbers that defines the x component
of the surface grid

Y

2–D array of real numbers that defines the y component
of the surface grid

axes_handle

Handle to the target axes in which to plot the surface

If you do not specify axes_handle, MATLAB^{®} uses
current axes.

Name,Value

Specify optional comma-separated pairs of Name,Value arguments,
where Name is the argument name and Value is the corresponding value.
Name must appear inside single quotes (' '). You can specify several
name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Compute the normal vectors of an expression representing a surface.

[nx, ny, nz] = surfnorm(peaks);

Assign these normals to the VertexNormals property which MATLAB® uses to calculate the surface lighting. Set the lighting algorithm to gouraud and add a light using camlight.

b = reshape([nx ny nz], 49,49,3);
figure
surf(ones(49),'VertexNormals',b,'EdgeColor','none');
lighting gouraud
camlight

Reverse the direction of the normals by calling surfnorm with
transposed arguments:

surfnorm(X',Y',Z')

The surface normals represent conditions at vertices
and are not normalized. Normals for surface elements that face away
from the viewer do not display.

surfl uses surfnorm to
compute surface normals when calculating the reflectance of a surface.