Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab, how to calculate AUC (Area Under Curve)?

I have the file data.txt with two columns and N rows, something like this:

0.009943796 0.4667975
0.009795735 0.46777886
0.009623984 0.46897832
0.009564759 0.46941447
0.009546991 0.4703958
0.009428543 0.47224948
0.009375241 0.47475737
0.009298249 0.4767201
[...]

Every couple of values in the file correspond to one point coordinates (x,y). If plotted, this points generate a curve. I would like to calculate the area under curve (AUC) of this curve.

So I load the data:

data = load("data.txt");
X = data(:,1);
Y = data(:,2);

So, X contains all the x coordinates of the points, and Y all the y coordinates.

How could I calculate the area under curve (AUC) ?

like image 249
DavideChicco.it Avatar asked Dec 28 '11 19:12

DavideChicco.it


2 Answers

Easiest way is the trapezoidal rule function trapz.

If your data is known to be smooth, you could try using Simpson's rule, but there's nothing built-in to MATLAB for integrating numerical data via Simpson's rule. (& I'm not sure how to use it for x/y data where x doesn't increase steadily)

like image 197
Jason S Avatar answered Oct 17 '22 22:10

Jason S


just add AUC = trapz(X,Y) to your program and you will get the area under the curve

like image 36
Simon Avatar answered Oct 17 '22 23:10

Simon