how to replace all elements with zeros after "ONE" (number) in every column of matrix???
1 回表示 (過去 30 日間)
古いコメントを表示
in each column of 2000*32 matrix there are so many "ONES" i want to replace all elements with zeros after first "ONE".
there might be so many "ONES" IN every column of matrix.
I want to replace after First "ONE" (ONE is number in column of matrix)
0 件のコメント
採用された回答
per isakson
2020 年 2 月 8 日
Try this
>> m = randi([0,1],[6,8])
m =
0 0 0 1 0 0 0 0
0 1 1 1 1 1 0 1
0 0 0 0 1 0 0 0
0 0 1 0 1 1 0 0
1 1 1 1 0 1 1 1
1 1 1 0 0 0 0 0
>> for jj = 1:8, r=find(m(:,jj)==1,1,'first'); m(r+1:6,jj)=0; end
>> m
m =
0 0 0 1 0 0 0 0
0 1 1 0 1 1 0 1
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
1 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0
>>
その他の回答 (1 件)
Stephen23
2020 年 2 月 8 日
>> mat = randi([0,1],[6,8])
mat =
1 0 0 0 0 1 0 0
1 0 0 1 0 0 0 1
0 0 1 0 0 0 1 1
0 0 0 0 1 0 0 1
1 1 1 0 0 0 1 0
1 1 0 0 0 0 0 1
>> out = mat .* (cumsum(mmat,1)==1)
out =
1 0 0 0 0 1 0 0
0 0 0 1 0 0 0 1
0 0 1 0 0 0 1 0
0 0 0 0 1 0 0 0
0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 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!