Area between two curves
Ältere Kommentare anzeigen
I was wondering if there was a simpler/faster way of calculating the area between the two curves at each point (both of which are normailsed so the total area is 1). I am currently using a simple for loop to get the area between each set of points for the two curves, then subtracting it to get the difference i.e.
for i = 1:length(normpeak)-1
resN(i) = trapz(time(i:i+1),peak1(i:i+1));
resF(i) = trapz(time(i:i+1),peak2(i:i+1));
end
res = resN-resF;
This works, but unfortunately it is very slow. I was reading up on the trapz function and from what I understood it calculates the total integral by performing something very similar to what i'm doing now (see image) but sums the data at the end.

Is there a way to stop trapz from performing this summing of the data, so I can speed up my code?
Akzeptierte Antwort
Weitere Antworten (1)
Binbin Qi
am 23 Apr. 2015
0 Stimmen
if you can get the points of every curve, you can use polyarea function to get the area, and then diff
1 Kommentar
Christian Reece
am 23 Apr. 2015
Kategorien
Mehr zu Numerical Integration and Differentiation finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!