How can i sum cells that equals in matrix
1 次查看(过去 30 天)
显示 更早的评论
if i have a matrix like that
2 2 2 2
1 1 1 1
0 0 1 0
how can i calculate the sum of rows that the values in all of their columns are equals.
for this example i want it will return 2
0 个评论
回答(2 个)
Roger Stafford
2018-1-9
You can also use the 'all' function:
sum(all(diff(a,1,2)==0))
1 个评论
Rik
2018-1-9
It might not matter at all, but I would like to point out that this is about twice as fast as my answer (at least on my machine on R2017b and R2012b).
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!