Cumsum at different starting indices, append all previous value.
1 view (last 30 days)
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
Answers (0)
See Also
Categories
Find more on Logical 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!