Calculating cumulative for a series of numbers

1 回表示 (過去 30 日間)
D.J
D.J 2018 年 8 月 27 日
回答済み: KSSV 2018 年 8 月 27 日
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)

回答 (1 件)

KSSV
KSSV 2018 年 8 月 27 日
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)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by