problem in finding the mode for the following matrix

2 次查看(过去 30 天)
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 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by