problem in finding the mode for the following matrix

1 Ansicht (letzte 30 Tage)
mahesh bvm
mahesh bvm am 9 Jan. 2014
Kommentiert: mahesh bvm am 9 Jan. 2014
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.

Akzeptierte Antwort

Patrik Ek
Patrik Ek am 9 Jan. 2014
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 Kommentare
mahesh bvm
mahesh bvm am 9 Jan. 2014
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 am 9 Jan. 2014
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....

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by