MATLAB Answers

0

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

Asked by altaf ahmed on 12 May 2019
Latest activity Edited by madhan ravi
on 13 May 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

  0 Comments

Sign in to comment.

1 Answer

Answer by Stephan
on 12 May 2019
Edited by Stephan
on 12 May 2019
 Accepted Answer

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 Comments

Show 1 older comment
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.
idx = a~=0;
a(idx) = a(idx) + 1;

Sign in to comment.