One way to think about it is in 2 steps:
1. Get from Green's Theorem to the integral expression that has xdy-ydx in it: see e.g. the equation on http://en.wikipedia.org/wiki/Green's_theorem just below "Possible formulas for the area of D include". Or look at http://mathworld.wolfram.com/GreensTheorem.html
2. Now get from the integral expression to the discrete Matlab formula above.
Do you understand one of these but not the other?
Ross
If the polygon surrounds the origin then what you have is clearly the polygon's area (if traveling in a counterclockwise direction.) If the origin lies outside the polygon, notice that the triangles' portions that lie outside the polygon are eventually all cancelled out by other triangles returning on the other side of the polygon with negative area values leaving only the area of the polygon itself. It's easier to draw a picture than to put it into words. So draw a picture and see how it works.
For Green's theorem look up the Wikipedia site at
http://en.wikipedia.org/wiki/Green's_theorem
at the first equation. Set functions M = x/2 and L = -y/2 and calculate the line integral going along a line segment from P1 to P2 and get, lo and behold, (x1*y2-y1*x2)/2 (after all the smoke clears away.) Adding these all up gives the closed line integral on the left side of that equation. With the given M and L the integral on the right side is simply the double integral over the area of the polygon of the quantity 1/2 - (-1/2) = 1, so it's just the polygon's area itself. QED
You should realize that Green's theorem as applied here is just a flat two-dimensional version of Stoke's theorem where the vector field has a component of x/2 in the y-axis direction and -y/2 in the direction of the x-axis. The area integral of the curl of this field over the interior of the polygon is simply the integral of 1 over that area and the line integral around the polygon boundary is Stoke's theorem line integral.
Roger Stafford