Save the first non-zero value in each column

3 次查看(过去 30 天)
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by