Cumsum at different starting indices, append all previous value.
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!