首页 > 其他 > 详细

Matlab setdiff中的陷阱——消除重复元素

时间:2015-03-24 14:55:00      阅读:635      评论:0      收藏:0      [点我收藏+]

       利用3σ原则剔除粗差时,想避免matlab程序中数组维数动态变化的情况(因这样会降低计算速度),想用setdiff进行两个集合快速运算,结果出人意料(小陷阱)。

       setdiff——find setdifference of two vectors

c = setdiff(A, B)  returns the values in A that are not in B. In set theory terms, 
c = A - B. Inputs A and B can be numeric or character vectors or cell arrays of strings. 
The resulting vector is sorted in ascending order.
setdiff()函数的说明中,只是说返回集合B中没有但集合A中有的数据。如果集合A中含有重复数据怎么办?这里没有提到,用例子来说明一下。

a=[2 2 2 2 2 2 2 4 5 6 9];
b=[4 5];
c=setdiff(a,b);

c=2 6 9
结果的确有点出人意料!

如果第一次使用该函数,务必注意,该函数会消融掉重复元素。


Matlab setdiff中的陷阱——消除重复元素

原文:http://blog.csdn.net/renwudao24/article/details/44590511

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!