How to find the position of specific entry in a Matrix?
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ammy
am 8 Mär. 2018
Kommentiert: Ammy
am 9 Mär. 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
Akzeptierte Antwort
Walter Roberson
am 8 Mär. 2018
A = [3 2 1;3 1 2;2 3 1];
[r, c] = find(A == 2);
output = [r, c]
2 Kommentare
Walter Roberson
am 8 Mär. 2018
A = [3 2 1;3 1 2;2 3 1];
[r, c] = find(A.' == 2);
output = [c, r];
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!