Filter löschen
Filter löschen

Find multiple true in same row

5 Ansichten (letzte 30 Tage)
Millone
Millone am 29 Mai 2015
Kommentiert: Millone am 29 Mai 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?

Akzeptierte Antwort

per isakson
per isakson am 29 Mai 2015
Bearbeitet: per isakson am 29 Mai 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

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by