How to find indices of similar values in a vector?

8 ビュー (過去 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
  1 件のコメント
Jan
Jan 2017 年 8 月 1 日
@Syed Fahad Hassan: Please post a question only once.

サインインしてコメントする。

採用された回答

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
  1 件のコメント
Syed Fahad Hassan
Syed Fahad Hassan 2017 年 8 月 1 日
Thanks Rob. This helped

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by