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

Click For Summary
SUMMARY

This discussion focuses on extracting the coordinates of zero values from a matrix in Mathematica. The matrix defined is M = {{9,6,0,1},{3,7,2,5},{1,0,2,8},{8,8,1,0}}. The command Position[M,0] retrieves the coordinates in the format {row,column}, resulting in {{1,3},{3,2},{4,4}}. To convert these coordinates to the preferred format {column,row}, the command Map[Reverse,Position[M,0] is used, yielding {{3,1},{2,3},{4,4}}.

PREREQUISITES
  • Understanding of matrix representation in Mathematica
  • Familiarity with the Position function in Mathematica
  • Knowledge of coordinate systems in programming
  • Basic experience with Mathematica syntax and functions
NEXT STEPS
  • Learn advanced matrix manipulation techniques in Mathematica
  • Explore the use of the Map function for data transformation in Mathematica
  • Investigate other coordinate extraction methods in Mathematica
  • Study the implications of row-column ordering in matrix operations
USEFUL FOR

Mathematics experts, data analysts, and anyone working with matrix operations in Mathematica will benefit from this discussion.

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 ·
Replies
10
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
7
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K