given matrix \(\begin {pmatrix} 0 & 39 & 0\\ 55 & 100 & 0\\ 34 & 0 & 0\\ 0 & 9 & 0\\ 0 & 0 & 50 \end {pmatrix} \) find the column index which contain values \(>0\) but do it from top row to the bottom row. Hence the result should be \(\left ( \overset {1st\ \operatorname {row}}{\overbrace {2}},\overset {2nd\ \operatorname {row}}{\overbrace {1,2}},\overbrace {1},\overbrace {2},\overbrace {3}\right ) \) this is becuase on the first row, nonzero is in second column, and on the second row, nonzero is at first and second column, and on the third row, nonzero is at the first column, and so on.
Mathematica mat={{0, 39, 0}, {55,100, 0}, {34,0, 0}, {0, 9, 0}, {0, 0, 50}}; Position[#,x_/;x>0]&/@mat; Flatten[%]
|
Out[18]= {2,1,2,1,2,3} |