How can i find the areas under single parts of a plot?
조회 수: 1 (최근 30일)
이전 댓글 표시
I have this vector P wich represent the istant power used by a certain load in 24 h.
I would like to obtain a vector a vector E [1x24] whit the area under the segment given by 2 consecutive element of P.
I tryed this
%Power
P=[ 0.6495 0.7393 0.7551 0.7947 0.7974 0.8713 1.0482 1.2621 1.6027 1.7189 1.5710 1.3070 1.4416 1.5684 1.608 1.6053 1.6581 2.2865 2.4925 2.6087 2.3288 2.1941 1.9671 1.6265];
%Hours
H=[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23];
%I can plot these 2 ad obtain
plot(H,P);
Now i can find the whole area of the plot whit "trapz" or the cumulative area whit "cumtrapz" like this
trapz(H,P)
cumtrapz(H,P)
As i said I would like to obtain instead a vector E [1x23] whit the area under the segment given by 2 consecutive element of P.
For example for the first 2 element
E1=trapz(P(1,1:2))
E2=trapz(P(1,2:3))
I would like to avoid to write manually each element of E, is it possible?
댓글 수: 0
채택된 답변
Voss
2022년 7월 2일
%Power
P=[ 0.6495 0.7393 0.7551 0.7947 0.7974 0.8713 1.0482 1.2621 1.6027 1.7189 1.5710 1.3070 1.4416 1.5684 1.608 1.6053 1.6581 2.2865 2.4925 2.6087 2.3288 2.1941 1.9671 1.6265];
%Hours
H=[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23];
diff(cumtrapz(H,P))
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!