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

추가 답변 (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