필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
altaf ahmed
altaf ahmed 2019년 5월 12일
편집: madhan ravi 2019년 5월 13일
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.
madhan ravi
madhan ravi 2019년 5월 13일
편집: madhan ravi 2019년 5월 13일
idx = a~=0;
a(idx) = a(idx) + 1;

댓글을 달려면 로그인하십시오.

추가 답변 (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