PDA

View Full Version : How to get a special coordinates {x,y} from a matrix in MATHEMATICA.


76Ahmad
Jan24-12, 09:06 PM
Hello every one, this question for a mathematics experts...

Suppose we have the matrix


M =
\left| {\begin{array}{cccc}
9 & 6 & 0 & 1 \\
3 & 7 & 2 & 5 \\
1 & 0 & 2 & 8 \\
8 & 8 & 1 & 0 \\
\end{array} } \right|


and we want to print only the coordinates that equal to 0

for our matrix it will be like that:(let say the raw is X, and the column is Y)

{3,1}
{2,3}
{4,4}

please help
thanks

Bill Simpson
Jan24-12, 11:31 PM
In[1]:= M={{9,6,0,1},{3,7,2,5},{1,0,2,8},{8,8,1,0}}; Position[M,0]

Out[2]= {{1,3},{3,2},{4,4}}

Mathematica uses {row,column} instead of {column,row}

If you prefer your order for some reason then

In[3]:= Map[Reverse,Position[M,0]]

Out[3]= {{3,1},{2,3},{4,4}}

76Ahmad
Jan25-12, 07:07 PM
Thanks Bill

It is work 100%