How to find the position of specific entry in a Matrix?

16 vues (au cours des 30 derniers jours)
Ammy
Ammy le 8 Mar 2018
Commenté : Ammy le 9 Mar 2018
I have a matrix like
A=[3 2 1;3 1 2;2 3 1];
I want to find the position of 2 in each row
I need
1 2
2 3
3 1
which indicates that at first row it is in second column, at second row it is is in third column and at third row it is in first column,
Thanks
  1 commentaire
Ammy
Ammy le 8 Mar 2018
output =
3 1
1 2
2 3
This indicates the position column wise but i want the position of entry rowwise

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 8 Mar 2018
A = [3 2 1;3 1 2;2 3 1];
[r, c] = find(A == 2);
output = [r, c]
  2 commentaires
Walter Roberson
Walter Roberson le 8 Mar 2018
A = [3 2 1;3 1 2;2 3 1];
[r, c] = find(A.' == 2);
output = [c, r];
Ammy
Ammy le 9 Mar 2018
Thank you very much

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Resizing and Reshaping Matrices 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