How can I calculate three different shaded areas?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
wd w
am 20 Sep. 2024
Kommentiert: Star Strider
am 20 Sep. 2024
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.
0 Kommentare
Akzeptierte Antwort
Star Strider
am 20 Sep. 2024
Try this —
T1 = readtable('example.xlsx')
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
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
.
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Numerical Integration and Differentiation 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!