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 CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by