problem in finding the mode for the following matrix
1 次查看(过去 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.
0 个评论
采纳的回答
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 :)
更多回答(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!