How can i find the index of a value in a matrix?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a matrix event(120x120) and i want know the position of the value 7 in each row (this means that i want know in which column it is). I know that in each row there is the value 7 but with the command "find" it finds the linear indices (ex. if in the position 1,2 there is a 7 with find the ans is 121 but i want that the answer is 2 because it search in each row). for example in the matrix: 1 7 3 4 5 6 7 8 9 8 5 7 2 4 5 6 7 8 if i seach for 7 i want an ans like this: 2 1 5
0 commentaires
Réponses (1)
M
le 13 Mar 2018
Modifié(e) : M
le 13 Mar 2018
In the find command, you can use:
[row,col,v] = find()
or you can use sub2ind and ind2sub functions to convert between subscripts and linear indices.
In your example :
"in the matrix 1 7 3 4 5 6 7 8 9 8 5 7 2 4 5 6 7 " if i seach for 7 i want an ans like this: 2 1 5 .
Why ? Your example is a vector.
Voir également
Catégories
En savoir plus sur Dates and Time 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!