How to find indices of similar values in a vector?

6 vues (au cours des 30 derniers jours)
Syed Fahad Hassan
Syed Fahad Hassan le 1 Août 2017
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

Réponse acceptée

Rob Campbell
Rob Campbell le 1 Août 2017
Modifié(e) : Rob Campbell le 1 Août 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
reps={};
for thisU=unique(x)
f=find(x==thisU);
if length(f)>1, reps{end+1}=f; end
end

Plus de réponses (0)

Catégories

En savoir plus sur Linear Algebra dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by