从阵列Matlab消除/删除重复项 [英] Eliminate/Remove duplicates from array Matlab
本文介绍了从阵列Matlab消除/删除重复项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从数组中删除重复的任何数字.
How can I remove any number that has duplicate from an array.
例如:
b =[ 1 1 2 3 3 5 6]
成为
b =[ 2 5 6]
推荐答案
使用unique
函数提取唯一值,然后计算数据的直方图以获取唯一值,并保留计数为1的值.
Use unique
function to extract unique values then compute histogram of data for unique values and preserve those that have counts of 1.
a =[ 1 1 2 3 3 5 6];
u = unique(a)
idx = hist(a, u) ==1;
b = u(idx)
结果
2 5 6
对于多列输入,可以这样做:
for multi column input this can be done:
a = [1 2; 1 2;1 3;2 1; 1 3; 3 5 ; 3 6; 5 9; 6 10] ;
[u ,~, uid] = unique(a,'rows');
idx = hist(uid,1:size(u,1))==1;
b= u(idx,:)
这篇关于从阵列Matlab消除/删除重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文