renwudao24的专栏

利用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结果的确有点出人意料!

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

接受失败等于回归真实的自我,接受失败等于打破完美的面具,

renwudao24的专栏

相关文章:

你感兴趣的文章:

标签云: