Save the first non-zero value in each column

1 Ansicht (letzte 30 Tage)
EldaEbrithil
EldaEbrithil am 20 Aug. 2020
Kommentiert: EldaEbrithil am 20 Aug. 2020
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

Akzeptierte Antwort

madhan ravi
madhan ravi am 20 Aug. 2020
(cumsum(matrix) == 1) .* matrix

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by