MATLAB: Does the color data get scaled when I am using the FILL3 function even if I specify the correct indices of the colormap

colorfill3MATLAB

I would like to obtain different colors for the surfaces created using FILL3 function without scaling the indices specified as the argument.
When I use the following code, I get two surfaces with black and copper (extremes of the colormap) though I have given correct indices for the colors expecting brown and orange.
colormap(copper(5));
fill3([-1 1 1 -1;-1 1 1 -1]',[-1 -1 1 1;-1 -1 1 1]',[1 1 1 1;-1 -1 -1 -1]',[3 4]);

Best Answer

By default, the color data mapping is set to be 'scaled', which means that the data given as the argument for the color is scaled according to the colormap. Changing the 'CDataMapping' property to 'direct' ensures that the values are not scaled. For example:
colormap(copper(5));
fill3([-1 1 1 -1;-1 1 1 -1]',[-1 -1 1 1;-1 -1 1 1]',[1 1 1 1;-1 -1 -1 -1]',...
[3 4],'CDataMapping','direct');
will produce the expected results. This code uses the 3rd and the 4th indices of the copper(5) colormap for the surfaces.