Finding matrix column index based on certain conditions

조회 수: 2 (최근 30일)
Lucas Carvalho
Lucas Carvalho 2017년 7월 30일
댓글: Lucas Carvalho 2017년 7월 31일
Hello guys,
I want to extract the column indexes of a matrix which contains necessarily one element equals to 1 and all the other equal to zero. Matrix example:
A =
1 1 1 0 0 0 0 1 0 0 0 0 0
0 -1 -1 -1 0 0 0 -1 1 0 0 0 0
0 0 0 1 0 -1 0 0 0 1 0 0 0
0 0 1 0 1 0 -1 0 0 0 1 0 0
0 0 0 0 0 1 1 0 0 0 0 1 0
0 1 0 0 -1 0 0 0 0 0 0 0 1
The columns of this matrix which obey these conditions are: 1,9,10,11,12 and 13.
How can I implement these rules into my code??
Thank you very much indeed!

채택된 답변

James Tursa
James Tursa 2017년 7월 31일
result = find(sum(A==1)==1 & sum(A==0)==(size(A,1)-1));

추가 답변 (1개)

Walter Roberson
Walter Roberson 2017년 7월 31일
find( sum(A == 1) == 1 & sum(A == 0) == size(A,1)-1 )

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by