Problem with calculating the negative are enclosed between a curve and the x-axis

3 ビュー (過去 30 日間)
Omar Hassan
Omar Hassan 2023 年 2 月 14 日
編集済み: Torsten 2023 年 2 月 15 日
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)));

採用された回答

Torsten
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 件のコメント
Omar Hassan
Omar Hassan 2023 年 2 月 15 日
This is what happens when I sort the value with more steeper curves
Torsten
Torsten 2023 年 2 月 15 日
編集済み: Torsten 2023 年 2 月 15 日
Then your measurement data are - eh, not the best.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by