How to remove duplicates in an array
显示 更早的评论
Ex: In the array x=[1 2 2 3 3 3 4 5], i want to eliminate all repeating elements (2,3) and retain non-repeating elements (1,4,5)
i.e., If x=[1 2 2 3 3 3 4 5], answer should be x=[1 4 5]
采纳的回答
更多回答(2 个)
Image Analyst
2013-7-2
0 个投票
Sounds like homework. As hints, I'd probably use max() to find the greatest integer and the histogram edges, histc() to get the counts, and ismember() to help with removal. It's just a few lines of code - see if you can do it.
Jan
2013-7-2
0 个投票
You can also SORT the values at first and obtain the sorting index as 2nd output. Then use DIFF to find equal elements. Finally you can remove them and restore the original order by using the sorting index.
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!