MATLAB Answers

How to find indices of similar values in a vector?

조회 수: 31(최근 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 1 Aug 2017
@Syed Fahad Hassan: Please post a question only once.

댓글을 달려면 로그인하십시오.

채택된 답변

Rob Campbell
Rob Campbell 1 Aug 2017
편집: Rob Campbell 1 Aug 2017
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
for thisU=unique(x)
if length(f)>1, reps{end+1}=f; end

  댓글 수: 1

Syed Fahad Hassan
Syed Fahad Hassan 1 Aug 2017
Thanks Rob. This helped

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by