Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
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.

Réponse acceptée

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

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by