0

if i have x data

x = [a, b, c, d ...]

and y data

y= [a, b, c, d...]

and assumes that this is the plot of that x and y

enter image description here

How can i get or determine the area under the curve? thanks in advance!

Raldenors
  • 311
  • 1
  • 4
  • 15

1 Answers1

1

You just might try out trapz(x,y).

http://www.mathworks.com/matlabcentral/answers/154089-area-under-curve-no-function

  • 2
    Will `trapz` give the correct answer given that `x` is not strictly increasing? – zelanix Nov 11 '15 at 13:33
  • is it applicable for this kind of non-linear graph? thanks – Raldenors Nov 11 '15 at 13:37
  • 2
    To answer my own question, a quick test indicates that it does work for your non-linear graph. Try `x = [1 2 3 4 5 6 7]; y = [1 2 3 4 5 6 7]; plot(x, y); trapz(x, y)` then `x = [1 2 3 4 3 6 7]; y = [1 2 3 4 5 6 7]; plot(x, y); trapz(x, y)`. You can easily calculate the difference in area from the graph and verify that it works correctly. – zelanix Nov 11 '15 at 13:40
  • An edit showing how to use `trapz` would be more fruitful. Simply pointing to documentation isn't useful. – rayryeng Nov 11 '15 at 17:01