www.gusucode.com > graphics 案例源码程序 matlab代码 > graphics/ControlFaceColorsOfPolygonsExample.m
%% Different Polygon Face Colors % Create two polygons and use a different color for each polygon face. Use % a colorbar to show how the colors map into the colormap. % Copyright 2015 The MathWorks, Inc. %% % Create the polygons using matrices |x| and |y|. Specify |c| as an column % vector with two elements since there are two polygon faces, and add a % colorbar. x = [2 5; 2 5; 8 8]; y = [4 0; 8 2; 4 0]; c = [0; 1]; figure patch(x,y,c) colorbar %% % Alternatively, you can get the same result when using |f| and |v| % instead. When you create the polygons, set |FaceVertexCData| to a column % vector with two elements since there are two polygon faces. Set % |FaceColor| to |'flat'|. v = [2 4; 2 8; 8 4; 5 0; 5 2; 8 0]; f = [1 2 3; 4 5 6]; col = [0; 1]; figure patch('Faces',f,'Vertices',v,'FaceVertexCData',col,'FaceColor','flat'); colorbar