MATLAB Answers

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 20 Aug 2020
(cumsum(matrix) == 1) .* matrix
  댓글 수: 1
EldaEbrithil
EldaEbrithil 20 Aug 2020
Thank you very much Madhan!!

댓글을 달려면 로그인하십시오.

추가 답변(0개)

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by