From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Area under line/within lines
Date: Wed, 20 Apr 2011 18:01:20 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 33
Message-ID: <ion71g$mi7$>
References: <>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1303322480 23111 (20 Apr 2011 18:01:20 GMT)
NNTP-Posting-Date: Wed, 20 Apr 2011 18:01:20 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: comp.soft-sys.matlab:722969

"J.H." <> wrote in message <>...
> Hi,
> I have the following problem, for which I hope there is a matlab
> function to solve it.
> I have a line consisting of x and y coordinates, but for 1 x
> coordinate, there are multiple y coordinates and vice versa. Is there
> a smart way to compute the area underneath (or better: enclosed by)
> the line?
> Best regards,
> Jaap
- - - - - - - - - -
  From your remarks I deduce that this is not a straight line but rather a series of line segments between discrete points and (perhaps) they constitute a closed polygon.

  Let us suppose that x and y are column vectors of equal length that represent coordinates of the successive vertices of such a closed polygon and that they are ordered around the polygon in counterclockwise order.  I'm also supposing the polygon doesn't cross itself anywhere along its length, except that the last point should be equal to the first point.

  The enclosed area can be calculated as:

 x1 = x(1:end-1); y1 = y(1:end-1);
 x2 = x(2:end); y2 = y(2:end);

 a = 1/2*sum((x1+x2).*diff(y));

or equivalently

 a = 1/2*sum(x1.*y2-x2.*y1);

or even

 a = -1/2*sum((y1+y2).*diff(x));

  Note that if the points' order is clockwise, these will give the negative of the area.

Roger Stafford