How can i find the areas under single parts of a plot?
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Voss
on 2 Jul 2022
%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 Comments
More Answers (0)
See Also
Categories
Find more on Frequently-used Algorithms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!