Save the first non-zero value in each column

1 回表示 (過去 30 日間)
EldaEbrithil
EldaEbrithil 2020 年 8 月 20 日
コメント済み: EldaEbrithil 2020 年 8 月 20 日
Hi all
i have a matrix like that
1 0 1
0 1 0
0 0 0
1 0 1
i want to save only the first non zero values in each column and obtain:
1 0 1
0 1 0
0 0 0
0 0 0
How can i do that?
Thank you for the help
Regards

採用された回答

madhan ravi
madhan ravi 2020 年 8 月 20 日
(cumsum(matrix) == 1) .* matrix
  1 件のコメント
EldaEbrithil
EldaEbrithil 2020 年 8 月 20 日
Thank you very much Madhan!!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by