Check and replace elements in a matrix
古いコメントを表示
I have a random generated matrix (2x8) which consist of zeros and ones. How can I check, in each row, if there are 2 ones in the first 4 elements and 1 one in the last 4 elements ? Moreover, If there are more ones than the prescribed, I would like to exchange the redundants ones with zeros.
i.e rand = ( 1 1 1 0 0 1 1 0; 0 1 1 1 0 1 0 0 )
modified_rand = ( 1 1 0 0 0 1 0 0; 0 1 1 0 0 1 0 0 )
Any help could be useful. Thanks in advance !
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Image Arithmetic についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!