MATLAB Answers

how to find area under the curve ?

7 views (last 30 days)

Accepted Answer

John D'Errico
John D'Errico on 9 Jun 2021
Easy. Just use trapz.
help trapz
TRAPZ Trapezoidal numerical integration. Z = TRAPZ(Y) computes an approximation of the integral of Y via the trapezoidal method (with unit spacing). To compute the integral for spacing different from one, multiply Z by the spacing increment. For vectors, TRAPZ(Y) is the integral of Y. For matrices, TRAPZ(Y) is a row vector with the integral over each column. For N-D arrays, TRAPZ(Y) works across the first non-singleton dimension. Z = TRAPZ(X,Y) computes the integral of Y with respect to X using the trapezoidal method. X can be a scalar or a vector with the same length as the first non-singleton dimension in Y. TRAPZ operates along this dimension. If X is scalar, then TRAPZ(X,Y) is equivalent to X*TRAPZ(Y). Z = TRAPZ(X,Y,DIM) or TRAPZ(Y,DIM) integrates across dimension DIM of Y. The length of X must be the same as size(Y,DIM)). Example: Y = [0 1 2; 3 4 5] trapz(Y,1) trapz(Y,2) Class support for inputs X, Y: float: double, single See also SUM, CUMSUM, CUMTRAPZ, INTEGRAL. Documentation for trapz doc trapz Other functions named trapz codistributed/trapz gpuArray/trapz

More Answers (1)

SALAH ALRABEEI
SALAH ALRABEEI on 9 Jun 2021
Use polyarea(x,y); you need to have a polygon; That is, ur first point must by ur lasr point. You can do so by adding this to ur x y data x(end+1)=x(1);y(end+1)=y(1);
Then apply the polyarea function

Community Treasure Hunt

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

Start Hunting!

Translated by