Finding indices in a magic 5x5 matrix in which the values are greater than 20?

7 次查看(过去 30 天)
There is a 5x5 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.

采纳的回答

Geoff Hayes
Geoff Hayes 2014-6-17
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by