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

In summary, to extract specific coordinates from a matrix in Mathematica, you can use the "Part" function. Multiple coordinates can be extracted at once by using a list of coordinates inside double brackets. To extract a specific row or column, use the "Part" function with a single index. A range of coordinates can be extracted using the "Span" operator. To extract coordinates based on a certain condition, use the "Pick" function.
  • #1
76Ahmad
48
0
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
 
Physics news on Phys.org
  • #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}}
 
  • #3
Thanks Bill

It is work 100%
 

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

1. How do I extract specific coordinates from a matrix in Mathematica?

To extract specific coordinates from a matrix in Mathematica, you can use the "Part" function. For example, if you have a matrix called "matrix" and you want to extract the coordinate at row 2 and column 3, you would use the syntax "matrix[[2,3]]". This will return the value at that specific coordinate.

2. Can I extract multiple coordinates from a matrix at once in Mathematica?

Yes, you can extract multiple coordinates at once in Mathematica by using a list of coordinates inside the double brackets. For example, if you want to extract the coordinates at row 1 and column 2, and row 3 and column 4, you would use the syntax "matrix[[{1,3},{2,4}]]". This will return a list of the values at those coordinates.

3. How can I extract a specific row or column from a matrix in Mathematica?

To extract a specific row or column from a matrix in Mathematica, you can use the "Part" function with a single index. For example, if you want to extract the 3rd row of a matrix called "matrix", you would use the syntax "matrix[[3]]". Similarly, if you want to extract the 4th column, you would use "matrix[[All,4]]".

4. Is there a way to extract a range of coordinates from a matrix in Mathematica?

Yes, you can extract a range of coordinates from a matrix in Mathematica by using the "Span" operator. This operator is denoted by two colons (::) and allows you to specify a range of values. For example, if you want to extract the coordinates from rows 2 to 4 and columns 1 to 3, you would use the syntax "matrix[[2;;4,1;;3]]". This will return a matrix with those specified coordinates.

5. How do I extract coordinates based on a certain condition in Mathematica?

To extract coordinates based on a certain condition in Mathematica, you can use the "Pick" function. This function takes in a list of elements and a list of conditions, and returns the elements that satisfy those conditions. For example, if you want to extract all coordinates from a matrix called "matrix" that are greater than 5, you would use the syntax "Pick[matrix, matrix>5]". This will return a list of all coordinates that satisfy the condition.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
370
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Special and General Relativity
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
142
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
3K
  • Linear and Abstract Algebra
Replies
5
Views
971
Back
Top