フィルターのクリア

remove elements from a matrix

4 ビュー (過去 30 日間)
Carlos_conde
Carlos_conde 2017 年 10 月 17 日
コメント済み: Carlos_conde 2017 年 10 月 17 日
Hello,
I have a matrix 1080x840 filled with 0 and 1, like:
[1 1 1 1 1 1 0 0 0 0 0 ;
1 1 1 1 1 1 1 1 0 0 0 1;
1 1 1 1 1 0 0 0 1 0 0 1;
1 1 1 1 1 1 0 0 0 1 0 1]
where a "zero' appears I would like to change the ones located in the right of the zero to zero. So, the new matrix would be:
[1 1 1 1 1 1 0 0 0 0 0;
1 1 1 1 1 1 1 1 0 0 0 0;
1 1 1 1 1 0 0 0 0 0 0 0;
1 1 1 1 1 1 0 0 0 0 0 0]
How can I do that?

採用された回答

Stephen23
Stephen23 2017 年 10 月 17 日
編集済み: Stephen23 2017 年 10 月 17 日
Very simply using cumprod:
>> M = [1,1,1,1,1,1,0,0,0,0,0,0;1,1,1,1,1,1,1,1,0,0,0,1;1,1,1,1,1,0,0,0,1,0,0,1;1,1,1,1,1,1,0,0,0,1,0,1]
M =
1 1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 1 1 1 0 0 0 1
1 1 1 1 1 0 0 0 1 0 0 1
1 1 1 1 1 1 0 0 0 1 0 1
>> cumprod(M,2)
ans =
1 1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 1 1 1 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0 0
1 1 1 1 1 1 0 0 0 0 0 0
  1 件のコメント
Carlos_conde
Carlos_conde 2017 年 10 月 17 日
Thanks a lot

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by