keep first time a value appear in a colomn and replace following ones
조회 수: 1 (최근 30일)
이전 댓글 표시
Good evening, Supposing I have the following matrix A= 5*3 =[1 1 1; 1 1 1; 1 0 1 ; 1 0 0; 1 0 0] What i want to do is to keep the first zero of each colomn and to replace following zeros by 1, so that i get a matrix B =5*3= [1 1 1; 1 1 1; 1 0 1 ; 1 1 0; 1 1 1]
Thank you in advance
댓글 수: 0
답변 (2개)
Jos (10584)
2015년 5월 29일
This will keep the first zero in each row of A and replace every following zero with one:
A(A==0 & cumsum(A==0,2)>1) = 1
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!