Suppose an index vector in binary like below
Input
1 1 0 0 1 0 1
1 2 3 4 5 6 7
Intended output
1 2 5 7
which denotes n
th number to be chosen. So I want to change 1 1 0 0 1 0 1
to 1 2 5 7
, is there some easy way for this?
Suppose an index vector in binary like below
Input
1 1 0 0 1 0 1
1 2 3 4 5 6 7
Intended output
1 2 5 7
which denotes n
th number to be chosen. So I want to change 1 1 0 0 1 0 1
to 1 2 5 7
, is there some easy way for this?
If you actually want to use your output to index another vector, do it directly.
You just need to transform your binary vector to logical
A = [1 1 0 0 1 0 1]; %assuming its double
B = [1 2 3 4 5 6 7];
C = B( logical(A) )
C =
1 2 5 7
The solution is using the function find(indicesBinary)