Matlab,如何计算AUC(曲线下面积)? [英] Matlab, how to calculate AUC (Area Under Curve)?
问题描述
我有两个列N行的文件data.txt
,如下所示:
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
[...]
文件中的每对值都对应一个点坐标(x,y). 如果已绘制,则这些点将生成一条曲线.我想计算该曲线的曲线下面积(AUC).
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.
所以我加载数据:
data = load("data.txt");
X = data(:,1);
Y = data(:,2);
因此,X
包含所有点的x坐标,而Y
包含所有y坐标.
So, X
contains all the x coordinates of the points, and Y
all the y coordinates.
如何计算曲线下面积(AUC)?
How could I calculate the area under curve (AUC) ?
推荐答案
最简单的方法是梯形规则函数 trapz
.
Easiest way is the trapezoidal rule function trapz
.
如果已知您的数据是平滑的,则可以尝试使用Simpson规则,但是MATLAB内置没有任何东西可以通过Simpson规则集成数值数据. (&我不确定如何将其用于x/y数据,而x不会稳定增加)
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)
这篇关于Matlab,如何计算AUC(曲线下面积)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!