keep first time a value appear in a colomn and replace following ones
2 ビュー (過去 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 で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!