필터 지우기
필터 지우기

problem in finding the mode for the following matrix

조회 수: 2 (최근 30일)
mahesh bvm
mahesh bvm 2014년 1월 9일
댓글: mahesh bvm 2014년 1월 9일
Consider a matrix JJ
JJ
JJ =
2.3159 1.9527 1.8476 1.9527
2.7977 0.8633 0.0298 0.8633
0.0438 1.0645 0.0438 0.0880
0.7228 2.0592 0.7228 0.2329
0.2228 1.4990 0.2228 0.0414
Now,I need find the mode in each row. I tried this already by giving the command mode(JJ,2). The answer I got is this.
mode(JJ,2)
ans =
1.9527
0.0298
0.0438
0.2329
0.0414
As it can be seen the answer is wrong with respect to 2nd, 4th and 5th rows. The common elements or mode of 2nd, 4th and 5th is 0.8633, 0.7228 and 0.2228 respectively. Why the mode command is showing a wrong answer??
Any help is highly appreciated.

채택된 답변

Patrik Ek
Patrik Ek 2014년 1월 9일
It works for me with the given atrix. Are you sure this is the exact values of JJ? Otherwise you need to truncate it to a tolerance. This is done as
newMtx = round(1/tol*mtx)*tol;
truncation to 4 decimals would then be have tol = 1/10^4
newMtx = round((10^4)*mtx)/10^4;
Thank you for accepting the answer :)
  댓글 수: 3
mahesh bvm
mahesh bvm 2014년 1월 9일
Patrick.... You made my day!!!!! your suggestion to use tolerance level did bring out great results..... I checked that with varied values of 'n' and all the answers were perfect!. Thank you, Thank you so much!
mahesh bvm
mahesh bvm 2014년 1월 9일
Thank you jos for your help too... I will check out your code too. ......
Guys check this new problem "Problem in aligning the data files one below the other.." posted by me, it seems a small problem is present in terms of aligning the plots one below the other....

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by