3-D Visualization Previous page   Next Page

Indexed Color Data

MATLAB interprets indexed color data as either values to scale before mapping to the colormap, or directly as indices into the colormap. You control the interpretation by setting the CDataMapping property. The default is to scale the data.

Scaled Color

By default, MATLAB scales the color data so that the minimum value maps to the first color in the colormap, the maximum value maps to the last color in the colormap, and values in between are linearly transformed to span the colormap. This enables you to use colormaps of different sizes without changing your data and to use data in any range of values without changing the colormap.

For example, the following patch has eight triangular faces with a total of 24 (nonunique) vertices. The color data are integers that range from one to 24, but could be any values.

The variable c contains the color data. It is a 3-by-8 matrix, with each column specifying the colors for the three vertices of each face.

The color bar (colorbar) on the right side of the patch illustrates the colormap used and indicates with the vertical axis which color is mapped to the respective data value.

You can alter the mapping of color data to colormap entry using the caxis command. This command uses a two-element vector [cmin cmax] to specify what data values map to the beginning and end of the colormap, thereby shifting the color mapping.

By default, MATLAB sets cmin to the minimum value and cmax to the maximum value of the color data of all graphics objects within the axes. However, you can set these limits to span any range of values and thereby shift the color mapping. See "Calculating Color Limits" in "Axes Properties" in the Using MATLAB Graphics documentation for more information.

The color data does not need to be a sequential list of integers; it can be any matrix with dimensions matching the coordinate data. For example,

Direct Color

If you set the patch CDataMapping property to direct,

MATLAB interprets each color data value as a direct index into the colormap. That is, a value of 1 maps to the first color, a value of 2 maps to the second color, and so on.

The patch from the previous example would then use only the first 24 colors in the colormap.

This example uses integer color data. However, if the values are not integers, MATLAB converts them according to these rules:

Unscaled color data is more commonly used for images where there is typically a colormap associated with a particular image.


Previous page  Interpreting Indexed and Truecolor Data Truecolor Patches Next page

© 1994-2005 The MathWorks, Inc.