To find the position of the elements which are same in vector
조회 수: 3 (최근 30일)
이전 댓글 표시
I have a vector like this: a = [ 2 3 4 2 5 4 3 3]; and I want to find all the index of the elements which has the same value. output like this: # 2, [1 4] # 3, [2 7 8] # 4, [3 6] # 5, [5]
댓글 수: 0
채택된 답변
추가 답변 (2개)
per isakson
2012년 9월 12일
편집: per isakson
2012년 9월 12일
Try
num = [ 2 3 4 2 5 4 3 3 ];
unq = unique( num );
ii = arrayfun( @(x) find( num==x ), unq, 'uni', false ) ;
>> unq
unq =
2 3 4 5
>> ii{:}
ans =
1 4
ans =
2 7 8
ans =
3 6
ans =
5
or use a for-loop
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!