Calculating cumulative for a series of numbers

1 visualización (últimos 30 días)
D.J
D.J el 27 de Ag. de 2018
Respondida: KSSV el 27 de Ag. de 2018
Hi all, I am trying to write a code to determine at which date the cumulative series of numbers reaches the value 6, but I have no idea where to start. Say for example I have a matrix of 2 columns: date= 1/07/2017 to 30/1/2017 col2= [1:30] The code should calculate the cumulative numbers in "col2" and show at which day the sum exceeds 6.
Any help would be highly appreciated. Many thanks
t1 = datetime(2017,07,1,8,0,0);
t2 = datetime(2017,07,31,8,0,0);
t = t1:t2
t_Col=t'
col2=col2=rand(31,1)

Respuestas (1)

KSSV
KSSV el 27 de Ag. de 2018
N = 100 ; % numebr of tiem stamps
t = 1:N ;
val = rand(1,N) ;
A = cumsum(val) ;
idx = A<=6 ; % cumulative sum less then 6
iwant = t(idx)

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by