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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by