Unique numbers in array

1 回表示 (過去 30 日間)
Joseph Pauwels
Joseph Pauwels 2014 年 4 月 23 日
回答済み: Image Analyst 2014 年 4 月 24 日
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?

採用された回答

Image Analyst
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))

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 4 月 23 日
編集済み: Azzi Abdelmalek 2014 年 4 月 23 日
out= unique(A)
Or
out=unique(A,'rows')

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by