Given a numeric vector x, treat each element x(i) as a mass located at index i.
Compute the center-of-mass index
idx = sum(i * abs(x(i))) / sum(abs(x(i)))
If all elements are zero, return NaN.
Solution Stats
Problem Comments
2 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers1
Suggested Problems
-
Center-of-Mass Index of a Vector
1 Solvers
More from this Author4
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Edward, in the first test, the vector x is commented out.
It looks like your other problems have the same issue.