Problem with calculating the negative are enclosed between a curve and the x-axis
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Omar Hassan
am 14 Feb. 2023
Bearbeitet: Torsten
am 15 Feb. 2023
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 Kommentare
Akzeptierte Antwort
Torsten
am 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!