Cumulative sum between two trues in array according to positions stored in logical array
3 次查看(过去 30 天)
显示 更早的评论
Hello!
I would like to find a fast way to get cumulative sums of values of an array according to the starting and ending positions given by a logical array,
for instance:
v=[0;1;2;0;2;4;5;6;2;3;4];
pos=[true;false;true;false;false;true;false;true;false;false;true];
I would like the code to cumulative sum vector "x" between two trues, getting the following result:
result=[3;8;15;15]; %I summed [2+1+0;4+2+0+2;6+5+4;4+3+2+6]
Hope that the question is clear, thank you!
0 个评论
采纳的回答
更多回答(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!