Area under and above curve

Dear all, if [x,y] is a matrix of values, I want to evaluate the positive and negative areas under the curve. If I use area(x,y), is the result the difference between positive and negative areas under the curves? Thanks

Réponses (2)

Image Analyst
Image Analyst le 11 Juin 2016

0 votes

How are you defining "under" and "above"? Without any bound, the area would be infinite. What is a negative area? Do you mean the areas between the curve and the x axis? And exactly what does "Evaluate" mean to you? Do you just want the sum of the absolute value of y? Like perhaps
theArea = sum(abs(y)) * (x(2)-x(1)); % If x are uniformly spaced.
There are other options such as
theArea = cumtrapz(x, abs(y));
Maybe you can attach a diagram to illustrate what you want, if the above code doesn't work for you.

3 commentaires

Vera
Vera le 11 Juin 2016
Modifié(e) : Image Analyst le 11 Juin 2016
Thanks for answer.
In attach an illustration of my curve.
Positive area is between the curve (y positive) and the x axis and negative area is between curve (y negative) and x axis.
I want to calculate the positive area (sum of each sub-areas under the peak) and the and the negative area. Is the result of area(y) in matlab a numerical value that describes the difference between positive and negative area?
Thanks
Image Analyst
Image Analyst le 11 Juin 2016
Modifié(e) : Image Analyst le 11 Juin 2016
Try this:
% Compute area between positive y data and x axis:
positiveArea = sum(y(y>0))
% Compute area between negative y data and x axis:
negativeArea = sum(y(y<0))
Again, if you want the area as "triangles" instead of "bars", or have non-uniformly spaced x values, use cumtrapz().
Vera
Vera le 13 Juin 2016
Thanks. I tried to calculate the total area with two options: sum(y)=-1.21150 e-4 trapz(y)=-1.1801 e-4 Which is the best way to calculate the area.sum and trapz are based on different hypothesys of approximation? Thanks

Connectez-vous pour commenter.

Vera
Vera le 16 Juin 2016

0 votes

I have another question. Considering due curve (blu and black in the attached file). How can i Calculate and plot the area between the two curves? If y1 and y2 are the blu and dark curves respectively is: a = trapz(t,y2)-trapz(t,y1); the correct way? If yes how I can plot this area? Thanks

4 commentaires

Image Analyst
Image Analyst le 16 Juin 2016
Depends on how you want to calculate the sum. What's wrong with sum(abs(y1-y2))?
Vera
Vera le 17 Juin 2016
Modifié(e) : Vera le 17 Juin 2016
sum(abs(y1-y2)) doesn't work as I want. I need a way to calculate and visualiza area between y2 and y1 curves
Image Analyst
Image Analyst le 17 Juin 2016
"how I can plot this area?" <== area is a single number, unless you have some other definition. You can still use plot() to plot a single number though. Or you can use bar() or stem(). Check out the MATLAB plot gallery for more options:
Vera
Vera le 19 Juin 2016
With "how can I plot this area I mean how to fill area between the two curves" in order to visualize if the area is correct.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Get Started with Signal Processing Toolbox dans Centre d'aide et File Exchange

Tags

Question posée :

le 11 Juin 2016

Commenté :

le 19 Juin 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by