필터 지우기
필터 지우기

Find multiple true in same row

조회 수: 5 (최근 30일)
Millone
Millone 2015년 5월 29일
댓글: Millone 2015년 5월 29일
I am trying to detect if there is more than one true in the same column of a matrix:
A=[1 0 0; 1 0 0]
r= sum(A,2);
check=sum(r>1)
if check ==0
out= 'single';
else
out='multiple';
but it does not work I do not understand why? And to achieve the same for columns I have used:
col= sum(A);
check=sum(col>1)
if check ==0
out= 'single'
else
out='multiple'
this seems to work for columns.
Is there a better way to check separately if there are multiple true in rows and columns?

채택된 답변

per isakson
per isakson 2015년 5월 29일
편집: per isakson 2015년 5월 29일
Hint:
>> A=[1 0 0; 1 0 1]
A =
1 0 0
1 0 1
>> B = A==1
B =
1 0 0
1 0 1
>> sum( B, 1 )
ans =
2 0 1
>> sum( B, 2 )
ans =
1
2
>>
with A(end,end)==1
  댓글 수: 1
Millone
Millone 2015년 5월 29일
Thanks for the hint

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by