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 delete it from b (e.g. a = [2 3 5], b = [1 8 6 2 3 7], results b = [1 8 6 7]).
How can it be implemented in Matlab?
Use setdiff to find elements in one set but not the other.
setdiff(b, a)
Use intersect with 3 output arguments to get the indices of the elements to be deleted:
[c, ia, ib] = intersect(a, b);
b (ib) = [];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With