how to find index of 50% of sum of signal?

1 次查看(过去 30 天)
how to find index of 50% of sum of signal
a=[4 2 3 1 5 6 11];
sum(a)=32
50% of sum signal =16
indice which is approximately equal to of sum of 50% of sum signal a is 5

回答(2 个)

Walter Roberson
Walter Roberson 2021-11-26
Hint:
4, 2, 3, 1, 5, 6, 11
4, 4+2, 4+2+3, 4+2+3+1, 4+2+3+1+5, 4+2+3+1+5+6, 4+2+3+1+5+6+11 -->
4, 6, 9, 10, 15, 21, 32
4<=32/2, 6<=32/2, 9<=32/2, 10<=32/2, 15<=32/2, 21<=32/2, 32<=32/2 -->
true, true, true, true, true, false, false
1 2 3 4 5

Image Analyst
Image Analyst 2021-11-27
Isn't this a duplicate?
If it's not your homework, you can use my solution:
a=[4 2 3 1 5 6 11];
s = sum(a)
c = cumsum(a)
[minDiff, index] = min(abs(c - s/2))
If it is your homework, tag it as homework and find a different way.

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by