How to calculate area under the curve for bins
2 次查看(过去 30 天)
显示 更早的评论
Apologies for my wording; I am relatively new to MATLAB. My problem is:
I've used
AUC (:,i) = trapz(x, y);
and it obviously gives me the areas under the entire curve. I am trying to use a different 'y' (in that this y1 is divided into bins, and each bin is averaged to one value) to find the area under the curve of each bin. However, using trapz(x,y1) gives me the error LENGTH(X) must equal the length of Y in dim 1.. What other possibilities are there?
0 个评论
回答(1 个)
Jan
2017-3-14
[N, edges, bin] = histcounts(y, y1);
Result = splitapply(@mean, x, bin);
The first command finds the bins of y according to the coarser grid y1. Only the bin output is required. The second line calculates the averages over the bins.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!