www.gusucode.com > graphics 案例源码程序 matlab代码 > graphics/ControlFaceColorsWhenUsingCoordinateDataExample.m

    %% Interpolated Polygon Face Colors
% 

% Copyright 2015 The MathWorks, Inc.


%% 
% Interpolate colors across polygon faces by specifying a color at each polygon
% vertex, and use a colorbar to show how the colors map into the colormap.
%
% Create the polygons using matrices |x| and |y|. Specify |c| as a matrix
% the same size as |x| and |y| defining one color per vertex, and add a
% colorbar.

x = [2 5; 2 5; 8 8];
y = [4 0; 8 2; 4 0];
c = [0 3; 6 4; 4 6];
figure
patch(x,y,c)
colorbar

%%
% Alternatively, you can get the same result using |f| and |v| instead.
% When you create the polygons, set |FaceVertexCData| to a column vector
% with one value per vertex and set |FaceColor| to |'interp'|.

v = [2 4; 2 8; 8 4; 5 0; 5 2; 8 0];
f = [1 2 3; 4 5 6];
col = [0; 6; 4; 3; 4; 6];
figure
patch('Faces',f,'Vertices',v,'FaceVertexCData',col,'FaceColor','interp');
colorbar