Area under and above curve
Mostrar comentarios más antiguos
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
Respuestas (2)
Image Analyst
el 11 de Jun. de 2016
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 comentarios
Vera
el 11 de Jun. de 2016
Editada: Image Analyst
el 11 de Jun. de 2016
Image Analyst
el 11 de Jun. de 2016
Editada: Image Analyst
el 11 de Jun. de 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
el 13 de Jun. de 2016
Vera
el 16 de Jun. de 2016
0 votos
4 comentarios
Image Analyst
el 16 de Jun. de 2016
Depends on how you want to calculate the sum. What's wrong with sum(abs(y1-y2))?
Image Analyst
el 17 de Jun. de 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
el 19 de Jun. de 2016
Categorías
Más información sobre Get Started with Signal Processing Toolbox en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
