How to find indices of similar values in a vector?

조회 수: 7 (최근 30일)
Syed Fahad Hassan
Syed Fahad Hassan 2017년 8월 1일
댓글: Syed Fahad Hassan 2017년 8월 1일
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

채택된 답변

Rob Campbell
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 CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by