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

    %% Specifying Faces and Vertices
% Create a single polygon by specifying the coordinates of each unique
% vertex and a matrix that defines how to connect them. Then, add two more
% polygons to the figure. 
%
% Create a red square with corners at |(0,0)|, |(1,0)|, |(1,1)|, and
% |(0,1)|. Specify |v| so that each row defines the (_x,y_) coordinates for
% one vertex. Then, specify |f| as the vertices to connect. Set the color
% by specifying the |FaceColor| property.

% Copyright 2015 The MathWorks, Inc.


%%
v = [0 0; 1 0; 1 1; 0 1];
f = [1 2 3 4];
patch('Faces',f,'Vertices',v,'FaceColor','red')

%%
% Create two polygons by specifying |f| as a two-row matrix. Each row
% defines the face for one patch.

v2 = [2 4; 2 8; 8 4; 5 0; 5 2; 8 0];
f2 = [1 2 3; 
    4 5 6];
patch('Faces',f2,'Vertices',v2,'FaceColor','green')