This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Construct cdata and colormap for shaded relief


[cindx,cimap,clim] = shaderel(X,Y,Z,cmap)
[cindx,cimap,clim] = shaderel(X,Y,Z,cmap,[azim elev])
[cindx,cimap,clim] = shaderel(X,Y,Z,cmap,[azim elev],cmapl)
[cindx,cimap,clim] = shaderel(X,Y,Z,cmap,[azim elev],cmapl,clim)


[cindx,cimap,clim] = shaderel(X,Y,Z,cmap) constructs the colormap and color indices to allow a surface to be displayed in colored shaded relief. The colors are proportional to the magnitude of Z, but modified by shades of gray based on the surface normals to simulate surface lighting. This representation allows both large and small-scale differences to be seen. X, Y, and Z define the surface. cmap is the colormap used to create the new shaded colormap cimap. cindx is a matrix of color indices to cimap, based on the elevation and surface normal of the Z matrix element. clim contains the color axis limits.

[cindx,cimap,clim] = shaderel(X,Y,Z,cmap,[azim elev]) places the light at the specified azimuth and elevation. By default, the direction of the light is East (90º azimuth) at an elevation of 45º.

[cindx,cimap,clim] = shaderel(X,Y,Z,cmap,[azim elev],cmapl) chooses the number of grays to give a cimap of length cmapl. By default, the number of grayscales is chosen to keep the shaded colormap below 256. If the vector of azimuth and elevation is empty, the default locations are used.

[cindx,cimap,clim] = shaderel(X,Y,Z,cmap,[azim elev],cmapl,clim) uses the color limits to index Z into cmap.


Display the peaks surface with a shaded colormap:

[X,Y,Z] = peaks(100);
cmap = hot(16);
[cindx,cimap,clim] = shaderel(X,Y,Z,cmap);
surf(X,Y,Z,cindx); colormap(cimap); caxis(clim)
shading flat

More About

collapse all


This function effectively multiplies two colormaps, one with color based on elevation, the other with a grayscale based on the slope of the surface, to create a new colormap. This produces an effect similar to using a light on a surface, but with all of the visible colors actually in the colormap. Lighting calculations are performed on the unprojected data.

Introduced before R2006a

Was this topic helpful?