How to calculate area under each peak in plot from sampled data
Afficher commentaires plus anciens
Hi, I would like to know area of each peak from my sampled data [time,flow] plot as shown in picture. Area of each peak should be written to matrice [time_of_peak, area], so I would be able to plot graph.

Réponse acceptée
Plus de réponses (1)
Here is ax example
x = 0:20;
y = sin(x);
[xc,yc] = polyxpoly(x,y,[0 20],[0 0]); % find '0' points intersections
x1 = [xc' x]; % merge together
y1 = [yc' y];
[xx,ix] = sort(x1); % sort x coordinate
yy = y1(ix); % order y coordinate
ix1 = find(abs(yy)<0.01); % zero point indices
plot(xx,yy,'marker','.')
for i = 1:length(ix1)-1
ii = ix1(i):ix1(i+1); % indices of area
s = trapz(xx(ii),yy(ii)); % calculate area
text(xx(ix1(i)),yy(ix1(i)),num2str(s))
end
4 commentaires
Lukas Poviser
le 3 Avr 2021
Lukas Poviser
le 3 Avr 2021
darova
le 4 Avr 2021
xc and x are row and column. Try this
x1 = [xc(:); x(:)]; % merge together
y1 = [yc(:); y(:)];
Catégories
En savoir plus sur Descriptive Statistics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

