The slope2 function returns magnitudes of slope of a surface.
slope = slope2(x,y,z) slope = slope2(dx,dy,z) slope = slope2(...,'deg')
slope = slope2(x,y,z) returns a gridded local slope field for the surface z. The inputs x and y can be either vectors corresponding to the dimensions of z or a meshgrid of vectors corresponding to the dimensions of z. This function does not require x spacing to equal y spacing, however, it does assume uniform spacing in x and uniform spacing in y.
slope = slope2(dx,dy,z) specifies x and y spacing if dx and dy are scalars.
slope = slope2(...,'deg') returns slope in degrees. Default output is radians.
Here's a simple example of getting the 2D slope field in degrees:
% Load some sample data: [X,Y,Z] = peaks(1000); Z = Z/5; % Calculate local slopes: sl = slope2(X,Y,Z,'degrees'); % Plot surface slopes: surf(X,Y,Z,sl) shading flat cb = colorbar; % Make it pretty: ylabel(cb,'local slope (degrees)') camlight axis tight material dull view(-16,38)
This function was written by Chad A. Greene of the University of Texas Institute for Geophysics, July 2016.