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

1 次查看(过去 30 天)
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

采纳的回答

Stephan
Stephan 2019-5-12
编辑:Stephan 2019-5-12
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 个评论
altaf ahmed
altaf ahmed 2019-5-13
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by