# To calculate the area under a series of curves

1 view (last 30 days)
Vahid Esmaeili on 28 Jul 2020
Commented: Star Strider on 29 Jul 2020
Hello,
Would you please assist me to calculate the area under different sections of the curves of FR2_.mat? The sections are IC, LR, MS, TS, PS, P50, TOR.
The following lines calculate different sections of the curve like the photo attached to the question.
cycl=13;
for i=1:length(cycl)
if length(i+5)>length(FR2_)
break
end
LR(i)=find(FR2_(i,:)==max(FR2_(i,1:40)));
for j= LR:70
if FR2_(i,j+1)> FR2_(i,j)
MS(i)= find(FR2_(i,:)==( FR2_(i,j)));
end
end
end
for i=1:length(cycl)
IC(i)=find(FR2_(i,:)==min(FR2_(i,1:3)));
LR(i)=find(FR2_(i,:)==max(FR2_(i,1:40)));
TS(i)=find(FR2_(i,:)==max(FR2_(i,MS(i):85)));
PS(i)=find(FR2_(i,:)==max(FR2_(i,TS(i):99)));
P50(i)=find(FR2_(i,:)==min(FR2_(i,49:51)));
TOR(i)=find(FR2_(i,:)==min(FR2_(i,97:99)));
end
Also, there is a FL2_.mat. I have to find the points of FL2_.mat the correspond to the "IC, LR, MS, TS, PS, P50, TOR" points of FR2_. Then, I have to calculate area under these sections as well.
I appreciate your attention to this question.
Vahid, Star Strider on 28 Jul 2020
First, the for loops should both be:
for i = 1:cycl
The areas calculation appears to be straightforward:
for i=1:cycl
AUC = cumtrapz(FR2_(i,:));
IC(i)=find(FR2_(i,:)==min(FR2_(i,1:3)));
LR(i)=find(FR2_(i,:)==max(FR2_(i,1:40)));
TS(i)=find(FR2_(i,:)==max(FR2_(i,MS(i):85)));
PS(i)=find(FR2_(i,:)==max(FR2_(i,TS(i):99)));
P50(i)=find(FR2_(i,:)==min(FR2_(i,49:51)));
TOR(i)=find(FR2_(i,:)==min(FR2_(i,97:99)));
Areas(i,:) = diff(AUC([IC(i) LR(i) TS(i) PS(i) P50(i) TOR(i)]));
end
See if that does what you want.
.

Show 1 older comment
Star Strider on 29 Jul 2020
As always, my pleasure!
The variables:
[IC(i) LR(i) TS(i) PS(i) P50(i) TOR(i)]
appear to be the way you want to partition each of the 13 (1x100) vectors, so I left them that way, and calculated the ‘Areas’ vectors using them, since it was not obvious otherwise how you wanted the curves partitioned. The problem may be the way you calculate those indices.
There are 6 indices spanning almost the entire vector (from 1 to 99), so there would be 5 areas for each vector.
Note that ‘PS’ and ‘TS’ are the same (so a 0 area between them), and the ‘PS’ indices are greater than the ‘P50’ indices, leading to the negative result for that segment.
My code works correctly for the indices you calculated.
.
Vahid Esmaeili on 29 Jul 2020
I modified the calculation of variables and now everything is OK.
Thanks
Star Strider on 29 Jul 2020
As always, my pleasure!
I appreciate the follow-up!

KSSV on 28 Jul 2020