I can look for the position of a value, i.e. 45, in a vector 'data' using the '==' operator and the 'find()' function:
data = [ 71 65 23 45 34 12 21 34 52 ];
value = 45;
find (data == value)
ans = 4
Is there a way to do the same for several values without using a loop, i.e. i would like to get [ 4 5 7 ] in a single call:
values = [ 45 34 21 ];
find (data == values)
error: mx_el_eq: nonconformant arguments (op1 is 1x9, op2 is 1x3)
error: evaluating argument list element number 1
error: evaluating argument list element number 1
Try the ismember function:
data = [ 71 65 23 45 34 12 21 34 52 ];
values = [ 45 34 21 ];
find(ismember(data, values))
Giving:
ans =
4 5 7 8
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