필터 지우기
필터 지우기

how to find the second most repeated value in vector

조회 수: 41 (최근 30일)
mary m
mary m 2017년 8월 25일
댓글: Ambati Sathvik 2020년 7월 2일
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

채택된 답변

Stephen23
Stephen23 2017년 8월 25일
편집: Stephen23 2017년 8월 25일
>> [n,bin] = hist(x,unique(x));
>> [~,idx] = sort(-n);
>> n(idx) % count instances
ans =
3 2 1 1
>> bin(idx) % corresponding values
ans =
5 2 1 3
>>

추가 답변 (4개)

Walter Roberson
Walter Roberson 2017년 8월 25일
Delete all the copies of m out of x and take the mode again.
  댓글 수: 1
Apoorva Srivastava
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
Andrei Bobrov 2017년 8월 25일
[g,v] = findgroups(x);
ii = accumarray(g(:),1);
jj = find(ii > 1);
out = [v(jj(2)), ii(jj(2))]

alexander Mcghee
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

mary m
mary m 2017년 8월 26일
thank you for all.. ^_^

카테고리

Help CenterFile Exchange에서 Financial Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by