Mathematica How to get a special coordinates {x,y} from a matrix in MATHEMATICA.

AI Thread Summary
The discussion centers on extracting the coordinates of zero values from a given 4x4 matrix using Mathematica. The matrix provided is M = {{9,6,0,1},{3,7,2,5},{1,0,2,8},{8,8,1,0}}. The initial command used is Position[M,0], which returns the coordinates in the format {row, column}. The output lists the coordinates of the zeros as {{1,3},{3,2},{4,4}}. For those who prefer the format {column, row}, a solution is provided using Map[Reverse,Position[M,0]], which yields the coordinates as {{3,1},{2,3},{4,4}}. The method is confirmed to work effectively.
76Ahmad
Messages
46
Reaction score
0
Hello every one, this question for a mathematics experts...

Suppose we have the matrix

<br /> M =<br /> \left| {\begin{array}{cccc}<br /> 9 &amp; 6 &amp; 0 &amp; 1 \\<br /> 3 &amp; 7 &amp; 2 &amp; 5 \\<br /> 1 &amp; 0 &amp; 2 &amp; 8 \\<br /> 8 &amp; 8 &amp; 1 &amp; 0 \\<br /> \end{array} } \right|<br />

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
 
Physics news on Phys.org
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}}
 
Thanks Bill

It is work 100%
 

Similar threads

Replies
10
Views
3K
Replies
1
Views
2K
Replies
9
Views
3K
Replies
2
Views
2K
Replies
2
Views
2K
Replies
1
Views
3K
Back
Top