how to get cumulative percentage

8 views (last 30 days)
how to get the cumulative percentage of g using this coding and plot it against t?
l=input('l=')
g = zeros(1, length(0:100));% initialize g with 0's of length t
c = 1;% counter variable
for t=0:100
if t>2 && t<=80
g(c)=((3/(309*1.465))*((((12.6*(t-2))/l)*80.4)-(l/6)));
elseif t>80
g(c)=1-((80.4/309)*exp(((((-3*12.6)/(1.465*l))*(t-80)))));
else
g(c)=0;
end
c = c+1;% increment counter variable
end
format shortG
g
t=0:100;
plot(t,g)

Accepted Answer

Mohammad Sami
Mohammad Sami on 30 Jan 2020
gs = cumsum(g);
gs = gs / gs(end) * 100;
plot(t,gs)
  2 Comments
liyana nadirah
liyana nadirah on 31 Jan 2020
but why the plot and the data in output not same?

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Object Programming 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!