Cumsum at different starting indices, append all previous value.
Show older comments
Hello, say I have 2 continuous dataset for example:
A = [0 0 8 0] B = [1 0 0 0 0.5 1.5 0]
The algorithm iterates over each element i = i +1 to check if element >= 0.5. If True cumsum starts.
Condition: Cumsum ends when exceeds 2 within 3 indices. Append the values and index.
The final cumsum value is not important, it is a means to set the condition of appending relevant values.
So result for A will give:
result = [0, 0, 8], idx = 1, 2, 3 NOT result = [ 0 0 8 '0']
However, if the condition is not met. Ignore the cumsum and move on to the next value.
e.g.: B will start 1st cumsum at [1]: 1 + 0 + 0 = 1. Which fails to meet the condition. Hence ignored.
It continues iterating, until reaching 0.5 which then starts another cumsum.
So result for B will give:
val = [1 0 0 0 0.5 1.5] NOT [1 0 0] [1 0 0 0 0.5 1.5 '0']
How can I approach this? Many thanks.
3 Comments
Jan
on 2 Mar 2021
I want to append all values until an element >= 0.5, then cumsum happens.
A = [0 0 8 0]
val = [0, 0, 8], idx = [1, 2, 3]
Here is no cumulative sum.
B = [1 0 0 0 0.5 1.5 0]
val = [1 0 0 0 0.5 1.5]
There are no added elements here also. If [1,0,0] is ignored, what happens with the 3rd zero?
Currently it is not getting clear to me, what you want to achieve.
Jonathan Cheong
on 3 Mar 2021
Edited: Jonathan Cheong
on 3 Mar 2021
Jonathan Cheong
on 3 Mar 2021
Answers (0)
Categories
Find more on Elementary Math in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!