How does the "find" command work with arrays?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
M2ohamad
le 4 Fév 2015
Modifié(e) : John D'Errico
le 5 Fév 2015
So here's my code:
A1 = [1 2; 3 4];
A2 = [0 1; 5 6];
GlobalProd = A1*A2;
IndividProd = A1.*A2;
M1 = find(IndividProd)
M2 = find(GlobalProd)
Here's the output:
M1 =
2
3
4
M2 =
1
2
3
4
I am wondering what values the find command was looking for, since I put the name of an array instead of a specific value?
Thank you.
0 commentaires
Réponse acceptée
John D'Errico
le 4 Fév 2015
Modifié(e) : John D'Errico
le 5 Fév 2015
Find looks for NON-zero values. It returns the index of those elements, as they are stored in memory. Remember that elements are stored down columns, so all elements of the first column are first, then the second column.
A linear index is the index of what you would get if you unrolled the array into a long column vector.
If you give find a second return argument, then it returns row and column indices for the non-zeros.
By the way, this is stated in the help, so you could have learned this as easily and more rapidly, simply by reading the help for find. A good way to learn these things is by reading the help, then try some test cases of your own.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrix Indexing 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!