How can return the maximum appearance number in the square matrix?

조회 수: 1 (최근 30일)
Salem
Salem 2015년 2월 26일
댓글: Salem 2015년 2월 28일
How can I find the most repeated number in nxn matrice? For example, if I have 3x3 matrix like this [1 2 3; 6 6 4; 4 7 6] In this case the most repeated number is 6. But if two or more numbers have repeated same time I want to retrieve the biggest one like next example [2 5 2; 7 8 4; 5 -1 0] In this case I want the function return the 5 because it is greater than 2 which both have the same number of appearances in the matrix. I appreciate your help in advance
  댓글 수: 2
Sad Grad Student
Sad Grad Student 2015년 2월 26일
편집: Sad Grad Student 2015년 2월 26일
It's easy.. I have a feeling you're trying to get us to do your assignment... ;)
Hint: Lookup:
You're welcome! :)
Salem
Salem 2015년 2월 27일
Thanks for reply I am doing research so I do not have any homework, but I am new in Coding and Matlab.

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

채택된 답변

per isakson
per isakson 2015년 2월 27일
편집: per isakson 2015년 2월 27일
"most repeated number in nxn matrice"
M = [1 2 3; 6 6 4; 4 7 6];
binranges = [min(M(:)):max(M(:))];
[num,ix] = max( histc( M(:), binranges ) )
val = binranges(ix)
the value, val, is repeated num times.
&nbsp
"retrieve the biggest one" the above code will retrieve the smallest
M = [1 2 3; 6 6 4; 4 7 6];
binranges = [min(M(:)):max(M(:))];
bincounts = histc( M(:), binranges );
[num,ix] = max( fliplr( bincounts ) );
val = binranges(ix)
I've not tested this

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by