I want to know the position of all the 1's in the matrix in form of rows and cols ??

조회 수: 1 (최근 30일)
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 ?

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2015년 4월 5일
A=[0 1 1 0;0 1 0 1]
[jj,ii]=ind2sub(size(A'),find(A'==1))
out=[ii jj]

추가 답변 (1개)

Image Analyst
Image Analyst 2015년 4월 5일
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.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by