Effacer les filtres
Effacer les filtres

Find multiple true in same row

5 vues (au cours des 30 derniers jours)
Millone
Millone le 29 Mai 2015
Commenté : Millone le 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?

Réponse acceptée

per isakson
per isakson le 29 Mai 2015
Modifié(e) : per isakson le 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
  1 commentaire
Millone
Millone le 29 Mai 2015
Thanks for the hint

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by