Number of maximum values and maximum values in each column

조회 수: 1 (최근 30일)
navan
navan 2015년 5월 5일
댓글: navan 2015년 5월 6일
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

채택된 답변

James Tursa
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
  댓글 수: 1
navan
navan 2015년 5월 6일
Thanks a lot James. It solved my issue. And i am sorry that it is a typo. Your answer is exactly right.thanks again

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by