How to calculate area-under-the-curve with crossing zeros
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello I am really bad at matlab and I am trying to create a script to calculate the area under the curve for my ERG data.
Here is my problem. I have time (x) and the response (y). The data goes to <0 and up >0, to form the b-wave. My idea is to collect after pass the zero point to the next zero, and calculate the area.
The problem is a have more then 1000 curves to analyzed and I can find a good solution to make a script.
Here is one example.
time (is always the same)
0.00E+00
7.83E-04
1.57E-03
2.35E-03
3.13E-03
3.91E-03
4.70E-03
5.48E-03
6.26E-03
7.05E-03
7.83E-03
8.61E-03
9.39E-03
1.02E-02
1.10E-02
1.17E-02
1.25E-02
1.33E-02
1.41E-02
1.49E-02
1.57E-02
1.64E-02
1.72E-02
1.80E-02
1.88E-02
1.96E-02
2.04E-02
2.11E-02
2.19E-02
2.27E-02
2.35E-02
2.43E-02
2.51E-02
2.58E-02
2.66E-02
2.74E-02
2.82E-02
2.90E-02
2.98E-02
3.05E-02
3.13E-02
3.21E-02
3.29E-02
3.37E-02
3.44E-02
3.52E-02
3.60E-02
3.68E-02
3.76E-02
3.84E-02
3.91E-02
3.99E-02
4.07E-02
4.15E-02
4.23E-02
4.31E-02
4.38E-02
4.46E-02
4.54E-02
4.62E-02
4.70E-02
4.78E-02
4.85E-02
4.93E-02
5.01E-02
5.09E-02
5.17E-02
5.25E-02
5.32E-02
5.40E-02
5.48E-02
5.56E-02
5.64E-02
5.71E-02
5.79E-02
5.87E-02
5.95E-02
6.03E-02
6.11E-02
6.18E-02
6.26E-02
6.34E-02
6.42E-02
6.50E-02
6.58E-02
6.65E-02
6.73E-02
6.81E-02
6.89E-02
6.97E-02
7.05E-02
7.12E-02
7.20E-02
7.28E-02
7.36E-02
7.44E-02
7.52E-02
7.59E-02
7.67E-02
7.75E-02
7.83E-02
7.91E-02
7.98E-02
8.06E-02
8.14E-02
8.22E-02
8.30E-02
8.38E-02
8.45E-02
8.53E-02
8.61E-02
8.69E-02
8.77E-02
8.85E-02
8.92E-02
9.00E-02
9.08E-02
9.16E-02
9.24E-02
9.32E-02
9.39E-02
9.47E-02
9.55E-02
9.63E-02
9.71E-02
9.79E-02
9.86E-02
9.94E-02
1.00E-01
1.01E-01
1.02E-01
1.03E-01
1.03E-01
1.04E-01
1.05E-01
1.06E-01
1.07E-01
1.07E-01
1.08E-01
1.09E-01
1.10E-01
1.10E-01
1.11E-01
1.12E-01
1.13E-01
1.14E-01
1.14E-01
1.15E-01
1.16E-01
1.17E-01
1.17E-01
1.18E-01
1.19E-01
1.20E-01
1.21E-01
1.21E-01
1.22E-01
1.23E-01
1.24E-01
1.25E-01
1.25E-01
1.26E-01
1.27E-01
1.28E-01
1.28E-01
1.29E-01
1.30E-01
1.31E-01
1.32E-01
1.32E-01
1.33E-01
1.34E-01
1.35E-01
1.35E-01
1.36E-01
1.37E-01
1.38E-01
1.39E-01
1.39E-01
1.40E-01
1.41E-01
1.42E-01
1.43E-01
1.43E-01
1.44E-01
1.45E-01
1.46E-01
1.46E-01
1.47E-01
1.48E-01
1.49E-01
1.50E-01
1.50E-01
1.51E-01
1.52E-01
1.53E-01
1.53E-01
1.54E-01
1.55E-01
1.56E-01
1.57E-01
1.57E-01
1.58E-01
1.59E-01
1.60E-01
1.61E-01
1.61E-01
1.62E-01
1.63E-01
1.64E-01
1.64E-01
1.65E-01
1.66E-01
1.67E-01
1.68E-01
1.68E-01
1.69E-01
1.70E-01
1.71E-01
1.71E-01
1.72E-01
1.73E-01
1.74E-01
1.75E-01
1.75E-01
1.76E-01
1.77E-01
1.78E-01
1.79E-01
1.79E-01
1.80E-01
1.81E-01
1.82E-01
1.82E-01
1.83E-01
1.84E-01
1.85E-01
1.86E-01
1.86E-01
1.87E-01
1.88E-01
1.89E-01
1.89E-01
1.90E-01
1.91E-01
1.92E-01
1.93E-01
1.93E-01
1.94E-01
1.95E-01
1.96E-01
1.97E-01
1.97E-01
1.98E-01
1.99E-01
2.00E-01
2.00E-01
2.01E-01
2.02E-01
2.03E-01
2.04E-01
2.04E-01
2.05E-01
2.06E-01
2.07E-01
2.07E-01
2.08E-01
2.09E-01
2.10E-01
2.11E-01
2.11E-01
2.12E-01
2.13E-01
2.14E-01
2.15E-01
2.15E-01
2.16E-01
2.17E-01
2.18E-01
2.18E-01
2.19E-01
2.20E-01
2.21E-01
2.22E-01
2.22E-01
2.23E-01
2.24E-01
2.25E-01
2.25E-01
2.26E-01
2.27E-01
2.28E-01
2.29E-01
2.29E-01
2.30E-01
2.31E-01
2.32E-01
2.33E-01
2.33E-01
2.34E-01
2.35E-01
2.36E-01
2.36E-01
2.37E-01
2.38E-01
2.39E-01
2.40E-01
2.40E-01
2.41E-01
2.42E-01
2.43E-01
2.43E-01
2.44E-01
2.45E-01
2.46E-01
2.47E-01
2.47E-01
2.48E-01
2.49E-01
2.50E-01
2.51E-01
2.51E-01
2.52E-01
2.53E-01
2.54E-01
2.54E-01
2.55E-01
2.56E-01
2.57E-01
2.58E-01
2.58E-01
2.59E-01
2.60E-01
2.61E-01
2.61E-01
2.62E-01
2.63E-01
2.64E-01
2.65E-01
2.65E-01
2.66E-01
2.67E-01
2.68E-01
2.69E-01
2.69E-01
2.70E-01
2.71E-01
2.72E-01
2.72E-01
2.73E-01
2.74E-01
2.75E-01
2.76E-01
2.76E-01
2.77E-01
2.78E-01
2.79E-01
2.80E-01
2.80E-01
2.81E-01
2.82E-01
2.83E-01
2.83E-01
2.84E-01
2.85E-01
2.86E-01
2.87E-01
2.87E-01
2.88E-01
2.89E-01
2.90E-01
2.90E-01
2.91E-01
2.92E-01
2.93E-01
2.94E-01
2.94E-01
2.95E-01
2.96E-01
2.97E-01
2.98E-01
2.98E-01
2.99E-01
3.00E-01
3.01E-01
3.01E-01
3.02E-01
3.03E-01
3.04E-01
3.05E-01
3.05E-01
3.06E-01
3.07E-01
3.08E-01
3.08E-01
3.09E-01
3.10E-01
3.11E-01
3.12E-01
3.12E-01
3.13E-01
3.14E-01
3.15E-01
3.16E-01
3.16E-01
3.17E-01
3.18E-01
3.19E-01
3.19E-01
3.20E-01
3.21E-01
3.22E-01
3.23E-01
3.23E-01
3.24E-01
3.25E-01
3.26E-01
3.26E-01
3.27E-01
3.28E-01
3.29E-01
3.30E-01
3.30E-01
3.31E-01
3.32E-01
3.33E-01
3.34E-01
3.34E-01
3.35E-01
3.36E-01
3.37E-01
3.37E-01
3.38E-01
3.39E-01
3.40E-01
3.41E-01
3.41E-01
3.42E-01
3.43E-01
3.44E-01
3.44E-01
3.45E-01
3.46E-01
3.47E-01
3.48E-01
3.48E-01
3.49E-01
3.50E-01
3.51E-01
3.52E-01
3.52E-01
3.53E-01
3.54E-01
3.55E-01
3.55E-01
3.56E-01
3.57E-01
3.58E-01
3.59E-01
3.59E-01
3.60E-01
3.61E-01
3.62E-01
3.62E-01
3.63E-01
3.64E-01
3.65E-01
3.66E-01
3.66E-01
3.67E-01
3.68E-01
3.69E-01
3.70E-01
3.70E-01
3.71E-01
3.72E-01
3.73E-01
3.73E-01
3.74E-01
3.75E-01
3.76E-01
3.77E-01
3.77E-01
3.78E-01
3.79E-01
3.80E-01
3.80E-01
3.81E-01
3.82E-01
3.83E-01
3.84E-01
3.84E-01
3.85E-01
3.86E-01
3.87E-01
3.88E-01
3.88E-01
3.89E-01
3.90E-01
3.91E-01
3.91E-01
3.92E-01
3.93E-01
3.94E-01
3.95E-01
3.95E-01
3.96E-01
3.97E-01
3.98E-01
3.98E-01
3.99E-01
4.00E-01
The response (y)
3.47E-06
2.30E-06
2.35E-06
5.96E-06
8.94E-06
9.14E-06
6.70E-06
-4.82E-07
-1.28E-05
-2.90E-05
-4.83E-05
-6.59E-05
-7.92E-05
-8.95E-05
-9.23E-05
-8.62E-05
-7.88E-05
-7.03E-05
-5.98E-05
-5.21E-05
-4.74E-05
-4.54E-05
-3.68E-05
-1.04E-05
3.65E-05
8.04E-05
9.46E-05
8.05E-05
4.84E-05
1.13E-06
-4.52E-05
-4.64E-05
2.76E-05
1.21E-04
1.65E-04
1.56E-04
1.21E-04
7.61E-05
2.42E-05
-2.26E-05
-3.85E-05
-1.65E-05
3.12E-05
7.58E-05
8.97E-05
8.06E-05
6.43E-05
4.48E-05
2.67E-05
1.60E-05
1.47E-05
2.31E-05
3.84E-05
5.41E-05
6.26E-05
6.54E-05
6.13E-05
5.37E-05
4.67E-05
4.20E-05
3.90E-05
3.79E-05
3.83E-05
4.13E-05
4.44E-05
4.72E-05
4.84E-05
4.83E-05
4.70E-05
4.57E-05
4.38E-05
4.23E-05
4.13E-05
4.02E-05
3.97E-05
3.90E-05
3.76E-05
3.68E-05
3.62E-05
3.56E-05
3.57E-05
3.53E-05
3.39E-05
3.19E-05
2.98E-05
2.86E-05
2.72E-05
2.65E-05
2.63E-05
2.62E-05
2.57E-05
2.43E-05
2.20E-05
1.91E-05
1.74E-05
1.65E-05
1.55E-05
1.57E-05
1.84E-05
2.03E-05
2.08E-05
2.10E-05
2.00E-05
1.75E-05
1.55E-05
1.42E-05
1.43E-05
1.35E-05
1.18E-05
1.05E-05
9.43E-06
8.60E-06
8.06E-06
7.87E-06
8.31E-06
7.92E-06
7.43E-06
6.50E-06
4.74E-06
3.38E-06
2.69E-06
2.25E-06
2.40E-06
1.76E-06
2.35E-06
2.20E-06
1.52E-06
-7.26E-07
-2.63E-06
-4.73E-06
-6.88E-06
-7.81E-06
-8.78E-06
-1.05E-05
-1.09E-05
-9.42E-06
-8.05E-06
-7.71E-06
-6.88E-06
-6.44E-06
-6.68E-06
-7.03E-06
-8.29E-06
-9.32E-06
-1.14E-05
-1.34E-05
-1.48E-05
-1.62E-05
-1.70E-05
-1.82E-05
-1.76E-05
-1.45E-05
-1.33E-05
-1.32E-05
-1.28E-05
-1.38E-05
-1.54E-05
-1.61E-05
-1.60E-05
-1.66E-05
-1.74E-05
-1.77E-05
-1.82E-05
-1.83E-05
-1.81E-05
-1.72E-05
-1.71E-05
-1.74E-05
-1.87E-05
-1.99E-05
-2.08E-05
-2.08E-05
-2.08E-05
-2.07E-05
-2.11E-05
-2.12E-05
-2.20E-05
-2.26E-05
-2.35E-05
-2.36E-05
-2.36E-05
-2.35E-05
-2.36E-05
-2.35E-05
-2.37E-05
-2.37E-05
-2.43E-05
-2.44E-05
-2.49E-05
-2.49E-05
-2.44E-05
-2.41E-05
-2.35E-05
-2.36E-05
-2.35E-05
-2.45E-05
-2.50E-05
-2.46E-05
-2.44E-05
-2.39E-05
-2.33E-05
-2.31E-05
-2.26E-05
-2.34E-05
-2.49E-05
-2.56E-05
-2.49E-05
-2.45E-05
-2.27E-05
-2.19E-05
-2.14E-05
-2.10E-05
-2.08E-05
-2.12E-05
-2.19E-05
-2.21E-05
-2.10E-05
-1.99E-05
-1.81E-05
-1.71E-05
-1.75E-05
-1.94E-05
-2.03E-05
-2.10E-05
-2.02E-05
-1.89E-05
-1.74E-05
-1.66E-05
-1.67E-05
-1.69E-05
-1.72E-05
-1.74E-05
-1.80E-05
-1.82E-05
-1.75E-05
-1.72E-05
-1.74E-05
-1.77E-05
-1.80E-05
-1.86E-05
-1.97E-05
-1.98E-05
-1.93E-05
-1.87E-05
-1.88E-05
-1.86E-05
-1.67E-05
-1.54E-05
-1.40E-05
-1.33E-05
-1.28E-05
-1.39E-05
-1.52E-05
-1.56E-05
-1.60E-05
-1.49E-05
-1.18E-05
-9.47E-06
-8.59E-06
-7.46E-06
-8.29E-06
-9.56E-06
-1.02E-05
-1.11E-05
-1.16E-05
-1.20E-05
-1.19E-05
-1.10E-05
-7.76E-06
-3.27E-06
-3.35E-07
1.67E-06
1.33E-06
-8.72E-07
-3.75E-06
-5.76E-06
-6.83E-06
-6.88E-06
-6.44E-06
-3.41E-06
-6.28E-07
1.67E-06
3.08E-06
3.03E-06
1.03E-06
-1.41E-06
-3.41E-06
-5.46E-06
-5.76E-06
-3.36E-06
-2.53E-06
-1.17E-06
2.64E-06
3.96E-06
4.16E-06
4.11E-06
3.33E-06
3.57E-06
4.60E-06
6.31E-06
8.16E-06
9.14E-06
8.36E-06
8.45E-06
8.50E-06
8.41E-06
8.31E-06
8.65E-06
9.14E-06
8.94E-06
9.43E-06
9.38E-06
9.33E-06
9.68E-06
9.38E-06
9.63E-06
9.38E-06
9.19E-06
9.87E-06
1.06E-05
1.10E-05
1.10E-05
1.03E-05
9.14E-06
8.36E-06
8.26E-06
8.75E-06
9.43E-06
1.02E-05
1.08E-05
1.04E-05
9.14E-06
8.06E-06
7.72E-06
7.72E-06
8.16E-06
9.33E-06
1.01E-05
1.04E-05
9.09E-06
7.72E-06
6.26E-06
5.04E-06
4.30E-06
4.35E-06
3.57E-06
3.13E-06
2.30E-06
1.08E-06
2.94E-06
5.38E-06
6.99E-06
9.04E-06
9.33E-06
8.89E-06
7.58E-06
6.89E-06
5.96E-06
5.09E-06
4.65E-06
4.11E-06
4.74E-06
5.23E-06
5.18E-06
4.60E-06
3.82E-06
3.28E-06
1.91E-06
1.67E-06
2.20E-06
3.77E-06
4.89E-06
4.99E-06
4.69E-06
3.82E-06
3.47E-06
2.79E-06
3.03E-06
3.08E-06
3.23E-06
3.72E-06
3.23E-06
1.52E-06
-1.07E-06
-3.22E-06
-4.88E-06
-5.12E-06
-1.85E-06
1.08E-06
2.74E-06
3.18E-06
1.96E-06
-1.56E-06
-4.93E-06
-7.12E-06
-6.39E-06
-3.07E-06
1.04E-07
2.35E-06
3.43E-06
3.23E-06
2.20E-06
6.90E-07
6.90E-07
5.44E-07
4.46E-07
3.00E-07
-3.35E-07
-1.41E-06
-1.80E-06
-2.19E-06
-2.39E-06
-2.24E-06
-2.19E-06
-2.68E-06
-2.92E-06
-3.46E-06
-3.36E-06
-3.66E-06
-3.36E-06
-2.92E-06
-1.85E-06
-1.61E-06
-1.75E-06
-2.19E-06
-3.17E-06
-3.31E-06
-3.46E-06
-2.87E-06
-1.65E-06
-9.21E-07
5.55E-08
-1.40E-07
-1.17E-06
-2.48E-06
-3.46E-06
-3.75E-06
-3.90E-06
-3.61E-06
-2.78E-06
-2.14E-06
-2.83E-06
-3.41E-06
-4.29E-06
-4.44E-06
-4.78E-06
-3.66E-06
-2.83E-06
-2.48E-06
-1.95E-06
-1.95E-06
-2.73E-06
-2.97E-06
-3.02E-06
-2.63E-06
-2.92E-06
-2.53E-06
-3.17E-06
-3.75E-06
-4.68E-06
-5.46E-06
-5.27E-06
-5.22E-06
-4.29E-06
-3.85E-06
-3.95E-06
-3.95E-06
-4.39E-06
-4.83E-06
-5.46E-06
-5.56E-06
-4.93E-06
-4.63E-06
-4.24E-06
-4.19E-06
-4.53E-06
-5.90E-06
-6.29E-06
-6.15E-06
-6.10E-06
-5.71E-06
-5.51E-06
-5.41E-06
-5.76E-06
-5.95E-06
-6.19E-06
-7.07E-06
-7.71E-06
-8.39E-06
-8.00E-06
-8.05E-06
-8.54E-06
-9.27E-06
-1.07E-05
-1.14E-05
-1.29E-05
-1.16E-05
-8.93E-06
-7.12E-06
-5.71E-06
-5.41E-06
-6.34E-06
-9.27E-06
-1.12E-05
-1.22E-05
-1.34E-05
-1.47E-05
-1.53E-05
-1.66E-05
-1.65E-05
-1.53E-05
-1.42E-05
Lets says I just want to calculate the area under the curve only between time point 0 to 0.1511. So selecting the first time it crosses zero and then finishing in the second time it crosses. then calculate the area.
I tried different combinations I found in the forum but i don´t get the results correctly.
One thing I tried was :
zeros = find( (y(1:end-1) ./ y(2:end)) <= 0 );
startingIndex = find(x==0);
endingIndex = find(x== 0.1511);
desiredx = x(startingIndex:endingIndex);
desiredy = y(startingIndex:endingIndex);
area = trapz(desiredx,desiredx);
plot(desiredx,desiredx,'b', x(zeros), 0, 'ro');
grid on;
I have the original data in excel files... Is really difficult for me to get the area correctly
also tried
area = trapz(find( (y(1:end-1) ./ y(2:end)) <= 0 ));
please if anybody knows how to help me I´ll really appreciate it
4 Commenti
Risposte (1)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!