MATLAB Language Drawing Polygon(s)


Example

Create vectors to hold the x- and y-locations of vertices, feed these into patch.

Single Polygon

X=rand(1,4); Y=rand(1,4);
h=patch(X,Y,'red');

single polygon

Multiple Polygons

Each polygon's vertices occupy one column of each of X, Y.

X=rand(4,3); Y=rand(4,3);
for i=2:3
  X(:,i)=X(:,i)+(i-1); % create horizontal offsets for visibility
end

h=patch(X,Y,'red');

three polygons