Find Unique values in array
조회 수: 12 (최근 30일)
이전 댓글 표시
Hi all,
I am trying to create a new array contains ONLY the unique values (same values but not repeated) which in the following case are 90 0 45
I used unique function, however, the function also returns the same data as in x, but in sorted order. I DO NOT want them in sorted order,
Also, I would like to obtain the index of the unique values in the x
like index=[1,2,9]
clear all;
clc;
x=[90 0 0 90 90 90 90 90 45 0 0 0];
y=unique(x)
댓글 수: 0
채택된 답변
Ameer Hamza
2020년 5월 12일
편집: Ameer Hamza
2020년 5월 13일
clc;
x=[90 0 0 90 90 90 90 90 45 0 0 0];
[y, idx] = unique(x, 'stable')
output
y =
90 0 45
idx =
1
2
9
댓글 수: 4
Ameer Hamza
2020년 5월 13일
Try try something like this
idx = [1 4];
for i=1:numel(idx)
z(:,:,i)=A(:,:,idx(i))
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!