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

    %% Specifying Coordinates
% Create a single polygon by specifying the (_x,y_) coordinates of each
% vertex. Then, add two more polygons to the figure.
%
% Create a red square with vertices at |(0,0)|, |(1,0)|, |(1,1)|, and
% |(0,1)|. Specify |x| as the _x_-coordinates of the vertices and |y| as
% the _y_-coordinates. |patch| automatically connects the last (_x,y_)
% coordinate with the first (_x,y_) coordinate.

% Copyright 2015 The MathWorks, Inc.


%%
x = [0 1 1 0];
y = [0 0 1 1];
patch(x,y,'red')

%%
% Create two polygons by specifying |x| and |y| as two-column matrices.
% Each column defines the coordinates for one of the polygons. 
% |patch| adds the polygons to the current axes without clearing the axes.

x2 = [2 5; 2 5; 8 8];
y2 = [4 0; 8 2; 4 0];
patch(x2,y2,'green')