Find multiple true in same row

3 views (last 30 days)
Millone
Millone on 29 May 2015
Commented: Millone on 29 May 2015
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?

Accepted Answer

per isakson
per isakson on 29 May 2015
Edited: per isakson on 29 May 2015
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

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!