How can I calculate three different shaded areas?

1 visualizzazione (ultimi 30 giorni)
I have three groups of sample points as attached, and intend to calculate three different shaded areas under curve from x = -40 to x = 30 by using for loop.

Risposta accettata

Star Strider
Star Strider il 20 Set 2024
Try this —
T1 = readtable('example.xlsx')
T1 = 6171x6 table
x1 y1 x2 y2 x3 y3 _______ ______ _______ ______ _______ ______ -69.644 10.562 -69.643 10.583 -69.631 10.605 -69.641 10.574 -69.641 10.596 -69.629 10.618 -69.639 10.586 -69.639 10.608 -69.626 10.631 -69.636 10.599 -69.636 10.621 -69.624 10.644 -69.634 10.611 -69.634 10.633 -69.622 10.657 -69.632 10.623 -69.632 10.645 -69.619 10.67 -69.629 10.636 -69.629 10.658 -69.617 10.683 -69.627 10.648 -69.627 10.67 -69.614 10.696 -69.625 10.66 -69.625 10.682 -69.612 10.709 -69.622 10.673 -69.622 10.694 -69.609 10.721 -69.62 10.685 -69.62 10.707 -69.607 10.734 -69.615 10.71 -69.615 10.732 -69.602 10.758 -69.61 10.734 -69.61 10.758 -69.597 10.783 -69.606 10.759 -69.605 10.784 -69.593 10.807 -69.601 10.784 -69.6 10.81 -69.588 10.831 -69.596 10.809 -69.595 10.836 -69.583 10.856
for k = 1:2:size(T1,2)
xv = T1{:,k};
yv = T1{:,k+1};
idxrng = (xv >= -40) & (xv <= 30);
AUC(ceil(k/2)) = trapz(xv(idxrng), yv(idxrng));
end
AUC
AUC = 1×3
98.2744 90.7472 80.9077
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
figure
tiledlayout(3,1)
for k = 1:2:size(T1,2)
% k
xv = T1{:,k};
yv = T1{:,k+1};
nexttile
plot(xv, yv)
hold on
idxrng = (xv >= -40) & (xv <= 30);
patch([xv(idxrng); flip(xv(idxrng))], [zeros(nnz(idxrng),1); flip(yv(idxrng))], 'r', 'FaceAlpha',0.5)
hold off
grid
end
.

Più risposte (0)

Prodotti


Release

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by