how to find the index of first n occurrence of each unique value of a matrix
이전 댓글 표시
I have a 5915x1 matrix and there are 42 unique values in the matrix.I want to find out first 75 occurences of each unique value. suppose i have a column matrix A as
A={1 2 3 4 1 1 2 2 5 5 5 5 4 6 7 8 4 6 4 }
Then for 1 : [1,5,6]
2:[2,7,8]
etc.
댓글 수: 1
Jan
2013년 4월 30일
Just to clarify: The elements are not unique, otherwise you cannot find 75 occurrences.
채택된 답변
추가 답변 (1개)
Andrei Bobrov
2013년 4월 30일
편집: Andrei Bobrov
2013년 4월 30일
A = randi(8,20,1); % eg
n = 4;
A1 = unique(A)
na = numel(A1);
out = [A1(:).';nan(n,na)];
for j1 = 1:na
k = find(A == A1(j1),n);
out(2:numel(k)+1,j1) = k;
end
out = out.';
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!