MATLAB: How to extract a single row from a matrix

binarymatrix

hey,
i need to extarct from binary matrix the row where i have '1' for example
y =
1 1 1
0 0 1
0 0 0
0 0 0
0 0 0
0 0 0
0 0 1
0 1 0
0 0 0
0 0 0
1 1 0
1 1 1
0 0 0
the matlab return the numer of line where i have the valeu '1'
thank you all!

Best Answer

Since ‘having a value of 1’ means 1 in the third column and no others (if I understand correctly what you want to do), multiply ‘y’ by the appropriate vector and test for the values that are equal to 1:
Result = y*[4 2 1]' == 1
Result =
0
1
0
0
0
0
1
0
0
0
0
0
0
If you want the row indices, use:
Result = find(Result)