How to calculate area under the curve for bins

2 vues (au cours des 30 derniers jours)
laura9510
laura9510 le 14 Mar 2017
Modifié(e) : Jan le 14 Mar 2017
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?

Réponses (1)

Jan
Jan le 14 Mar 2017
[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.
  2 commentaires
laura9510
laura9510 le 14 Mar 2017
Thank you for replying, I am so sorry but I meant how to calculate the area under the curve for each bin...
Jan
Jan le 14 Mar 2017
Modifié(e) : Jan le 14 Mar 2017
The area is the mean value multiplied by the width:
Result = splitapply(@mean, x, bin) .* diff(bin);
I cannot test this currently. Perhaps there is a problem with the dimensions.
If this does not match your question, perhaps a small example would be useful.

Connectez-vous pour commenter.

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by