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

3 visualizaciones (últimos 30 días)
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)));

Respuesta aceptada

Torsten
Torsten el 14 de Feb. de 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 comentarios
Omar Hassan
Omar Hassan el 15 de Feb. de 2023
This is what happens when I sort the value with more steeper curves
Torsten
Torsten el 15 de Feb. de 2023
Editada: Torsten el 15 de Feb. de 2023
Then your measurement data are - eh, not the best.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by