I want to know the position of all the 1's in the matrix in form of rows and cols ??
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Amir
am 5 Apr. 2015
Beantwortet: Image Analyst
am 5 Apr. 2015
For example;
A=[0 1 1 0;0 1 0 1]
how would i find that (1,2) , (1,3) , (2,2) , (2,4) are 1's ?
0 Kommentare
Akzeptierte Antwort
Azzi Abdelmalek
am 5 Apr. 2015
A=[0 1 1 0;0 1 0 1]
[jj,ii]=ind2sub(size(A'),find(A'==1))
out=[ii jj]
0 Kommentare
Weitere Antworten (1)
Image Analyst
am 5 Apr. 2015
How about simply using find():
[rows, columns] = find(A)
The results:
rows =
1
2
1
2
columns =
2
2
3
4
The rows and columns are synced up so that rows(k) and columns(k) refer to the row and column of the kth 1 in the array.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Matrices and Arrays 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!