# How to integrate the area below the peak when I dont have function of the peak?

9 vues (au cours des 30 derniers jours)
sanjay Krishnamurthy le 23 Mar 2022
I wanted to integrate the area below the shaded peak as shown in the image. The plot is taken from an experimental data so I dont have a function of my curve. How can I specify the limit and get the area below the shaded peak? The simple "trapz" function output is showing "NaN" and I understand I am not specifying the limits here. Can someone help me here. thank you.
% Integrate area below the peak
plot(AR_T,AR_mwmg) %AR_T and AR_mwmg are data stored in AR_data.mat file
int_AR = trapz(AR_T,AR_mwmg)
##### 3 commentairesAfficher 1 commentaire plus ancienMasquer 1 commentaire plus ancien
sanjay Krishnamurthy le 23 Mar 2022
So, How can I proceed to obtain my objective to find the area below the peak?
AndresVar le 23 Mar 2022

Connectez-vous pour commenter.

### Réponse acceptée

AndresVar le 23 Mar 2022
Modifié(e) : AndresVar le 23 Mar 2022
Use conditional indexing to define the limits of extent for the peak.
clear
% remove nan values (why is there a nan at the end?)
idxNotNan = ~isnan(AR_T) & ~isnan(AR_mwmg);
x = AR_T(idxNotNan);
y = AR_mwmg(idxNotNan);
%findpeaks(y,x,'Annotate','extents','WidthReference','halfheight','NPeaks',1,'SortStr','descend');
%[pkY, pkX, pkWidth, pkProm]=findpeaks(y,x,'NPeaks',1,'SortStr','descend')
idxPk = x>210 & x<325; % more or less...
xPk = x(idxPk);
yPk = y(idxPk);
figure;
plot(x,y,LineWidth=2,DisplayName='data')
hold on;
plot(xPk,yPk,'--',LineWidth=2,DisplayName='peak')
legend('show');
AreaFull=trapz(x,y)
AreaFull = 0.1168
AreaPk=trapz(xPk,yPk)
AreaPk = 0.1166
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
sanjay Krishnamurthy le 23 Mar 2022
Thank you so much for the detailed solution. it works well

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Numerical Integration and Differentiation 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