Number of maximum values and maximum values in each column
3 次查看(过去 30 天)
显示 更早的评论
I would like to get the no of maximum values for each column. i am using a 5*4 matrix A=
2 3 7 7 7,
5 8 8 8 1,
5 6 8 1 2,
2 1 8 1 4
And i expect an answer, i.e
noofmaximumvalueineachcolumn= 2 1 3 2 1
I am using a code
noofmaximumvalueineachcolumn=sum(A==max(A))
Which works only for a single row matrix.And it shows an error 'matrix dimensions must agree'. what should i do
0 个评论
采纳的回答
James Tursa
2015-5-5
编辑:James Tursa
2015-5-5
sum(bsxfun(@eq,A,max(A)))
But for your example I get 2 1 3 1 1, not 2 1 3 2 1
更多回答(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!