MATLAB: Finding indices in a magic 5×5 matrix in which the values are greater than 20

easy magic matrix 5x5values over 20 in a matrix

There is a 5×5 matrix, and I am trying to find the values that are greater than 20. Would I use something like >>A=magic(5)
A=1 1 1; 1 1 1; 1 1 1; >>[mx,i]=n>20(A) %return values greater than 20
%I don't currently have access to matlab, therefore I'm writing the code on paper ahead of time.

Best Answer

While the initialization of the magic A matrix is correct, the code that follows is unclear. Why the second initialization of A? What is n?
The easiest way to find those elements of A that are greater than 20 is to use the find function. In the Command Window, type doc find or help find for details on this function. The first example is similar to yours
A = magic(5);
[rIdcs,cIdcs] = find(A>20);
where rIdcs and cIdcs are the row and column indices respectively of those elements of A that are greater than 20.