Check to find if a row has an element occuring more than once

1 vue (au cours des 30 derniers jours)
altaf ahmed
altaf ahmed le 12 Mai 2019
Modifié(e) : madhan ravi le 13 Mai 2019
I need to find if a row has more than one occurence of 1s. I am expecting a response return like true or false. Sample row matrix is below:
0 0 1 1 0 0

Réponse acceptée

Stephan
Stephan le 12 Mai 2019
Modifié(e) : Stephan le 12 Mai 2019
A = [0 0 1 1 0 0; 0 0 0 0 0 1; 1 1 0 0 0 1]
res = (sum(A==1,2)>1)
This works row-wise for more than 1 rows
  4 commentaires
altaf ahmed
altaf ahmed le 13 Mai 2019
Followup question:
Once the non-zero elements of a row are identified, how can we increment all non-zero elemnts only by one. e.g.
a = [0 0 1 1 0 0]
becomes a = [0 0 2 2 0 0]
same operartion needs to be repeated in all rows.
madhan ravi
madhan ravi le 13 Mai 2019
Modifié(e) : madhan ravi le 13 Mai 2019
idx = a~=0;
a(idx) = a(idx) + 1;

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by