calculate the mode with tolerance

3 views (last 30 days)
Luca cadalo
Luca cadalo on 3 Mar 2017
Commented: Sai Sunku on 20 Mar 2020
I have a matrix A= [ 2 3 2.1 ; 8.1 3.3 2.05 ; 3.01 4.9 2.09] and I want to get the mode with a tolerance of 0.1 there is any way to get this??? to work in matlab with mode (the value most repeated) and tolerance thanks

Answers (1)

Jan
Jan on 3 Mar 2017
The question is not trivial. What do you expect as result for:
x = [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6]
?
You can round the values:
AA = round(A, 1)
and apply mode() afterwards, but this must not be necessarily, what you want.
  1 Comment
Sai Sunku
Sai Sunku on 20 Mar 2020
One can bin the data with the required tolerance and return the center of the bin with the highest frequency. I'm not particular about the tolerance, so I'm doing it as follows:
[N, edges] = histcounts(data);
[~, idx] = max(N); mode = (edges(idx) + edges(idx + 1))/2;
It would be nice if there was a built-in function for this.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!