Effacer les filtres
Effacer les filtres

Calculating cumulative for a series of numbers

1 vue (au cours des 30 derniers jours)
D.J
D.J le 27 Août 2018
Réponse apportée : KSSV le 27 Août 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)

Réponses (1)

KSSV
KSSV le 27 Août 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)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by