Given matrix \[ \left ( {\begin {array}{ccc} 1 & 5 \\ 2 & 3 \\ 4 & 8 \\ 7 & 2 \end {array}} \right ) \]
search in column 2 of matrix for the first time a value exceeds 6 and return the matrix up to that row. The result should be
\[ \left ( {\begin {array}{ccc} 1 & 5 \\ 2 & 3 \end {array}} \right ) \]
Mathematica a = {{1, 5}, {2, 3}, {4, 8}, {7, 2}}; Min@Position[a, {x_, y_} /; y > 6] (* 3 *) a[[1 ;; % - 1]]
|
{{1, 5}, {2, 3}} |