how to get cumulative percentage

8 visualizaciones (últimos 30 días)
liyana nadirah
liyana nadirah el 30 de En. de 2020
Comentada: liyana nadirah el 31 de En. de 2020
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)

Respuesta aceptada

Mohammad Sami
Mohammad Sami el 30 de En. de 2020
gs = cumsum(g);
gs = gs / gs(end) * 100;
plot(t,gs)
  2 comentarios
liyana nadirah
liyana nadirah el 30 de En. de 2020
tq. it work
liyana nadirah
liyana nadirah el 31 de En. de 2020
but why the plot and the data in output not same?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Graphics Object Programming en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by