2.14 Find all positions of elements in a Matrix that are larger than some value

The problem is to find locations or positions of all elements in a matrix that are larger or equal than some numerical value such as \(2\) in this example.

Mathematica

mat = {{1, 2,3}, 
       {2,1,-5}, 
       {6,0,0}}; 
 
p = Position[mat, _?(#1 >= 2&)]
 

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

 

Matlab

A=[1 2 3; 
   2 1 -5; 
   6 0 0] 
[I,J]=find(A>=2)
 

I = 
     2 
     3 
     1 
     1 
J = 
     1 
     1 
     2 
     3
 

 

Maple

Maple is little weak in this area. There does not seem to be a buildin function to return indices in matrix based on some condition. I searched ListTools and ArrayTools. So had to program it in.

A:=Matrix([[1,2,3],[2,1,-5],[6,0,0]]); 
seq(seq(`if`(A[i,j]>=2,[i,j],NULL),i=1..3),j=1..3);
 

 [2, 1], [3, 1], [1, 2], [1, 3]