How can i find the index of a value in a matrix?

1 vue (au cours des 30 derniers jours)
Stefano Sacchetti
Stefano Sacchetti le 13 Mar 2018
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

Réponses (1)

M
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.
  1 commentaire
Stefano Sacchetti
Stefano Sacchetti le 13 Mar 2018
your answer is what I was looking for, thank you!! when i wrote i put in 3 rows (in the preview message it was like [1 7 3 4 5 ; 7 8 9 8 5; 2 4 5 6 7 ]

Connectez-vous pour commenter.

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by