Matlab arrays operation

前端 未结 3 2085
野的像风
野的像风 2020-12-11 11:22

I have two arrays, a and b, of different size. Each one contains unique values.

I want to compare both and if any value of array a is in array b, then I want to dele

相关标签:
3条回答
  • 2020-12-11 11:33

    Use setdiff to find elements in one set but not the other.

    setdiff(b, a)
    
    0 讨论(0)
  • 2020-12-11 11:36

    Use intersect with 3 output arguments to get the indices of the elements to be deleted:

    [c, ia, ib] = intersect(a, b);
    b (ib) = [];
    
    0 讨论(0)
  • Yet another option is to use the ISMEMBER function to remove elements from b that are members of a via logical indexing:

    b(ismember(b,a)) = [];
    
    0 讨论(0)
提交回复
热议问题