MATLAB: Logical index multiple columns

indexinglogical indexinglogical?

We have a 111×1402 array A with one or no logical true for each column.
E.g.:
0 0 1 0 ...
1 0 0 0
0 1 0 1
.
.
.
Now we want to get the values for each of the 1402 columns from another array B which is 111×2.
Meaning the row of the 111 where there is a logical true in array A.
E.g.:
500 142
450 -12
305 125
. .
. .
. .
How can we achieve this in Matlab?

Best Answer

I believe you are trying to find the row-indices of A, where the row contains a 1, and then extract those rows from B. In that case, this should help:
B(any(A,2),:)