question of applying sum() to the matrix with zero values
4 次查看(过去 30 天)
显示 更早的评论
my matrix is X=[1 0 0 ;0 0 0;0 9 0](actual matrix is larger than this and having less values more zoros) my question is ,when applying sum(X),it gives error message "??? Subscript indices must either be real positive integers or logicals."
0 个评论
采纳的回答
Azzi Abdelmalek
2013-9-7
You've probably used sum as a variable in your code. Try this
clear sum
X=[1 0 0 ;0 0 0;0 9 0]
sum(X)
3 个评论
Image Analyst
2013-9-7
Be aware that sum will be over columns and will be a ax3 array. If you want the sum of the whole array, you can do this:
theSum = sum(X(:));
which turns X into a 1D vector before it gets summed. theSum will then be a scalar (single number) rather than a 1 by 3 array.
更多回答(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!