I have this vector:
t = 1: 10 % t = 1 2 3 ..10
A= [3 4 5] % a column vector
If I type:
(3 == t)
I get the result:
0 0 1 0 0 0 0 0 0 0 % it means: 1 at location equals, and 0 at others
I want to do this for vector a, meaning that it will take each element in vector A and compare and return another vector. So in this case, the result will be a 3×10 matrix.
But this line will result in an error: A==t
.
Of course, I can do this by using a for loop, but I want to vectorize this operation.
what you are looking for is the function ismember
octave> t = 1:10
t =
1 2 3 4 5 6 7 8 9 10
octave> A = ismember (t, [2 3 4])
A =
0 1 1 1 0 0 0 0 0 0
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