Problem with calculating the negative are enclosed between a curve and the x-axis
조회 수: 3 (최근 30일)
이전 댓글 표시
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
채택된 답변
Torsten
2023년 2월 14일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

