how to find the second most repeated value in vector
45 次查看(过去 30 天)
显示 更早的评论
how to find the second most repeated value in vector x=[1 2 2 3 5 5 5] i use (mode ) to find the most repeated and frequency [m,f]=mode(x) m=5 the number repeated f=3 the freq.
now,i want to find the second repeated, can help me please
0 个评论
采纳的回答
更多回答(4 个)
Walter Roberson
2017-8-25
Delete all the copies of m out of x and take the mode again.
1 个评论
Apoorva Srivastava
2019-6-16
编辑:Apoorva Srivastava
2019-6-16
% For a vector x:
mode(x(find(x ~= mode(x))))
% In general, if x is a matrix (valid from R2018b onwards)
mode(x(find(x ~= mode(x, 'all'))), 'all')
Andrei Bobrov
2017-8-25
[g,v] = findgroups(x);
ii = accumarray(g(:),1);
jj = find(ii > 1);
out = [v(jj(2)), ii(jj(2))]
0 个评论
alexander Mcghee
2019-9-17
X = [1 1 1 1 1 5 5 5] ;
m = mode(X) % -> m=1
X(X==m) = NaN ;
m = mode(X) % -> m=5
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Detection 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!