Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Calculating the area enclosed by a plot

Subject: Calculating the area enclosed by a plot

From: George

Date: 5 Jan, 2011 20:53:05

Message: 1 of 3

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.

Subject: Calculating the area enclosed by a plot

From: Sean de

Date: 5 Jan, 2011 21:42:05

Message: 2 of 3

"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!

Subject: Calculating the area enclosed by a plot

From: George

Date: 6 Jan, 2011 23:12:06

Message: 3 of 3

"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.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us