How to find indices of similar values in a vector?
    6 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    Syed Fahad Hassan
 am 1 Aug. 2017
  
    
    
    
    
    Kommentiert: Syed Fahad Hassan
 am 1 Aug. 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
1 Kommentar
  Jan
      
      
 am 1 Aug. 2017
				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.
Akzeptierte Antwort
  Rob Campbell
      
 am 1 Aug. 2017
        
      Bearbeitet: Rob Campbell
      
 am 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
reps={};
for thisU=unique(x)
     f=find(x==thisU);
     if length(f)>1, reps{end+1}=f; end
end
Weitere Antworten (0)
Siehe auch
Kategorien
				Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


