How to find indices of similar values in a vector?
조회 수: 6 (최근 30일)
이전 댓글 표시
I want to get the indices of similar values in a vector. For example, I have a vector x=[1 1 2 2 3]. The output should be something like this: indices = 1,2 & 3,4
댓글 수: 1
Jan
2017년 8월 1일
Duplicate question, see https://www.mathworks.com/matlabcentral/answers/351130-how-to-find-indices-of-similar-elements-in-a-vector
@Syed Fahad Hassan: Please post a question only once.
채택된 답변
Rob Campbell
2017년 8월 1일
편집: Rob Campbell
2017년 8월 1일
I'm unsure if you're looking for sequential numbers or not. The following just looks for repeats. Does it do what you want?
x = [1,1,2,2,3,4,5,6,1,2,3];
% Store in a cell array the indexes of values that repeat
reps={};
for thisU=unique(x)
f=find(x==thisU);
if length(f)>1, reps{end+1}=f; end
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Entering Commands에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!