Save the first non-zero value in each column

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

 Réponse acceptée

madhan ravi
madhan ravi le 20 Août 2020
(cumsum(matrix) == 1) .* matrix

Plus de réponses (0)

Catégories

En savoir plus sur Interpolation of 2-D Selections in 3-D Grids dans Centre d'aide et File Exchange

Produits

Version

R2019a

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by