Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

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

  1. Jan 24, 2012 #1
    Hello every one, this question for a mathematics experts...

    Suppose we have the matrix

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

    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
     
  2. jcsd
  3. Jan 24, 2012 #2
    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}}
     
  4. Jan 25, 2012 #3
    Thanks Bill

    It is work 100%
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




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