Unique numbers in array
조회 수: 2 (최근 30일)
이전 댓글 표시
I was charged to try and write my own unique function , I was thinking of first sorting the array, and then writing a loop that went through each number from min(min) to max(max) but cant figure out once a repeated number is identified to skip it. Any thoughts?
댓글 수: 0
채택된 답변
Image Analyst
2014년 4월 24일
That could work, but why use a for loop when there are so much more "MATLAB-ish" ways of doing it, like:
m = randi(4, 1, 11)
sortedm = sort(m)
diffs = [1, diff(sortedm)]
uniqueNumbers = sortedm(find(diffs))
댓글 수: 0
추가 답변 (1개)
Azzi Abdelmalek
2014년 4월 23일
편집: Azzi Abdelmalek
2014년 4월 23일
out= unique(A)
Or
out=unique(A,'rows')
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!