Problem with calculating the negative are enclosed between a curve and the x-axis
3 views (last 30 days)
Show older comments
Hey Guys,
I have a cyclic voltammetry curve which forms a pseudo-rectangle with one of the long sides above the x-axis and the other is below the x-axis. I want to calculate the positive and negative areas (the area between the positive part of the curve and the x-axis and the are between the negative part of the curve and the x-axis). For that, I use the commands shown below. However, when I compare the areas I get from my code to that I get from the electrochemistry software (EC-Lab) I found that the positive areas are quite matching, however, this is not the case with the negative area. I am getting 0.893 from the software for the positive area and 0.8897 from my code which seems close but for the negative area, I am getting 0.883539 from the software and 0.7927 from my code (around 10% difference). Is there a problem in my code or is it the trapz function that doesn't work well with negative values or is it a data problem (attached in an excel sheet) ?
Thanks in advance. 

gt0 = y>0;
gt1 = y<0;
Positive_area(1) = (trapz(x(gt0), y(gt0)));
Negative_area(1) = (trapz(x(gt1), y(gt1)));
0 Comments
Accepted Answer
Torsten
on 14 Feb 2023
Try
idx = y<=0;
jdx = y>=0;
xn = x(idx);
yn = y(idx);
xp = x(jdx);
yp = y(jdx);
[xn,I] = sort(xn);
yn = yn(I)
[xp,J] = sort(xp);
yp = yp(J);
figure(1)
plot(xn,yn)
figure(2)
plot(xp,yp)
trapz(xp,yp)
trapz(xn,yn)
5 Comments
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!