How to find indices of similar elements in a vector?
    조회 수: 3 (최근 30일)
  
       이전 댓글 표시
    
I have a vector x=[1 1 2 2 3]. I want to find out the indices of the elements that are similar. The desired output should be something like this. indices = 1,2 & 3,4
답변 (1개)
  Geoff Hayes
      
      
 2017년 8월 1일
        Syed - try the following
 x = [1 1 2 2 3];
 groupedData = arrayfun(@(y)find(x == y), unique(x), 'UniformOutput',false);
In the above, we use arrayfun to loop over each unique element of x and apply the function
 @(y)find(x == y)
which returns the indices of those elements of x that are identical to that unique element (the input y).
댓글 수: 0
참고 항목
카테고리
				Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


