calculate the mode with tolerance

3 次查看(过去 30 天)
Luca cadalo
Luca cadalo 2017-3-3
评论: Sai Sunku 2020-3-20
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

回答(1 个)

Jan
Jan 2017-3-3
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 个评论
Sai Sunku
Sai Sunku 2020-3-20
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.

请先登录,再进行评论。

类别

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