I have two matrices in Matlab:
q = [3 4 5];
w = [5 6 7];
I want to compare every element of q
with w
(i.e. 3 compared with 5, 6, and 7). If it matches any element in w
(like how 5 is in both q
and w
) then both q
and w
share 5 as a common key.
How can I compute all the common keys for q
and w
?
Try
>> x = intersect(q,w)
x =
5
This function treats the input vectors as sets and returns the set intersection. I think this is what you wanted to know. Is there a match yes/no? if x is empty (numel(x)==0) there was no match.
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