Summation of values > 1 in a cell array
1 次查看(过去 30 天)
显示 更早的评论
Suppose I've a cell array;
cnt{1}=[3;1;3;2;1;2]
I would like to sum up the values which are > 1 ie the answer should return 10 (3+3+2+2)
I've tried using 'find' but the answer only returns the indices of the values > 1 and not the values.
ind=(find(cnt{1}>1))
How can I go about this? Please give me some hint.
0 个评论
采纳的回答
Ilham Hardy
2013-4-12
sumVal = sum(cnt{1})-length(find(cnt{1}==1))
3 个评论
Ilham Hardy
2013-4-12
Yes, i agree. This way will be faster.
However i don't fully get the differences between example#1 and example#2. Care to explain?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!