COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Calculating the area enclosed by a plot

• Follow

```Recently I undertook the testing a a spring damper system. The tests involved cycling the unit with a sinusoidal displacement and recording the force.

From these tests plots are created which look like this: http://www.flickr.com/photos/57922959@N02/5328255652/

I need to find the area enclosed by the data, can Matlab do this?
I have tried to use the polyarea command to no success (areas that I know to be larger than others come out smaller)

Thanks
George.
```
 0

```"George " <mrhotpotato@hotmail.co.uk> wrote in message <ig2lnh\$lgp\$1@fred.mathworks.com>...
> Recently I undertook the testing a a spring damper system. The tests involved cycling the unit with a sinusoidal displacement and recording the force.
>
> From these tests plots are created which look like this: http://www.flickr.com/photos/57922959@N02/5328255652/
>
> I need to find the area enclosed by the data, can Matlab do this?
> I have tried to use the polyarea command to no success (areas that I know to be larger than others come out smaller)
>
> Thanks
> George.

help trapz
You'll have to call it twice: integrate the top part, subtract the integral of the bottom part.  The index that corresponds to the point between the two parts is:
[trash, idx] = max(x_values);
so
the_area = trapz(x(1:idx),y(1:idx))-trapz(x((idx+1):end),y((idx+1):end)

Good Luck!
```
 0

```"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <ig2ojd\$r6\$1@fred.mathworks.com>...
> "George " <mrhotpotato@hotmail.co.uk> wrote in message <ig2lnh\$lgp\$1@fred.mathworks.com>...
> > Recently I undertook the testing a a spring damper system. The tests involved cycling the unit with a sinusoidal displacement and recording the force.
> >
> > From these tests plots are created which look like this: http://www.flickr.com/photos/57922959@N02/5328255652/
> >
> > I need to find the area enclosed by the data, can Matlab do this?
> > I have tried to use the polyarea command to no success (areas that I know to be larger than others come out smaller)
> >
> > Thanks
> > George.
>
> help trapz
> You'll have to call it twice: integrate the top part, subtract the integral of the bottom part.  The index that corresponds to the point between the two parts is:
> [trash, idx] = max(x_values);
> so
> the_area = trapz(x(1:idx),y(1:idx))-trapz(x((idx+1):end),y((idx+1):end)
>
> Good Luck!

Thank you for the help. Worked Perfect.
George.
```
 0

2 Replies
962 Views

Similiar Articles:

7/23/2012 7:18:04 AM