www.gusucode.com > map 案例源码 matlab代码程序 > map/ComputeGradientDataFromRegularDataGridExample.m
%% Compute Gradient, Slope, and Aspect from Regular Data Grid % This example shows how to compute the gradient, slope, and aspect for a % regular data grid. The gradient components are the change in the grid % variable per meter of distance in the north and east directions. Slope is % defined as the change in elevation per unit distance along the path of % steepest ascent or descent from a grid cell to one of its eight immediate % neighbors, expressed as the arctangent. If the grid contains elevations % in meters, the aspect and slope are the angles of the surface normal % clockwise from north and up from the horizontal. The % <docid:map_ref.f13-860392> function uses a finite-difference approach to % compute gradients for either a regular or a georeferenced data grid. The % function returns the components of the gradient in the north and east % directions (i.e., north-to-south, east-to-west), as well as slope and % aspect. The angles are in units of degrees by default. %% % Construct a 100-by-100 grid using the |peaks| function and construct a % referencing matrix for it. % Copyright 2015 The MathWorks, Inc. datagrid = 500*peaks(100); gridrv = [1000 0 0]; %% % Generate grids containing aspect, slope, gradients to north, and % gradients to east. [aspect,slope,gradN,gradE] = gradientm(datagrid,gridrv); %% % Map the surface data in a cylindrical equal area projection. Start with % the original elevations. axesm eqacyl meshm(datagrid,gridrv) colormap (jet(64)) colorbar('vert') title('Peaks: elevation') axis square %% % Clear the frame and display the slope grid. clma meshm(slope,gridrv) colorbar('vert'); title('Peaks: slope') %% % Map the aspect grid. clma meshm(aspect,gridrv) colorbar('vert'); title('Peaks: aspect') %% % Map the gradients to the north. clma meshm(gradN,gridrv) colorbar('vert'); title('Peaks: North gradient') %% % Map the gradients to the east. clma meshm(gradE,gridrv) colorbar('vert'); title('Peaks: East Gradient')