Main Content

Combine Dissimilar Grids by Converting Regular Grid to Geolocated Data Grid

This example shows how to combine an elevation data grid and an attribute (color) data grid that cover the same region but are gridded differently. The example drapes slope data from a regular data grid on top of elevation data from a geolocated data grid. The example uses the geolocated data grid as the source for surface elevations and transforms the regular data grid into slope values, which are then sampled to conform to the geolocated data grid (creating a set of slope values for the diamond-shaped grid) and color-coded for surface display. This approach works with any dissimilar grids, although the two data sets in this example actually have the same origin (the geolocated grid derives from the topo60c data set).

Load the geolocated data grid from the mapmtx file and the regular data grid from the topo60c file. The mapmtx file actually contains two regions but this example only uses the diamond-shaped portion, lt1, lg1, and map1, centered on the Middle East.

load mapmtx lt1 lg1 map1 
load topo60c

Compute the surface aspect, slope, and gradients for topo60c. This example only uses the slopes in subsequent steps.

[aspect,slope,gradN,gradE] = gradientm(topo60c,topo60cR);

Use the geointerp function to interpolate slope values to the geolocated grid specified by lt1 and lg1 . The output is a 50-by-50 grid of elevations matching the coverage of the map1 variable.

slope1 = geointerp(slope,topo60cR,lt1,lg1);

Set up a figure with a Miller projection and use surfm to display the slope data. Specify the z -values for the surface explicitly as the map1 data, which is terrain elevation. The map mainly depicts steep cliffs, which represent mountains (the Himalayas in the northeast), and continental shelves and trenches.

axesm miller

The coloration depicts steepness of slope. Change the colormap to make the steepest slopes magenta, the gentler slopes dark blue, and the flat areas light blue:

colormap cool

Use view to get a southeast perspective of the surface from a low viewpoint. In 3-D, you immediately see the topography as well as the slope.


The default rendering uses faceted shading (no smooth interpolation). Render the surface again, this time making it shiny with Gouraud shading and lighting from the east (the default of camlight lights surfaces from over the right shoulder of the viewer).

material shiny
lighting Gouraud

Finally, remove white space and re-render the figure in perspective mode.

axis tight
ax = gca;
ax.Projection = 'perspective';