Save the first non-zero value in each column

1 visualización (últimos 30 días)
EldaEbrithil
EldaEbrithil el 20 de Ag. de 2020
Comentada: EldaEbrithil el 20 de Ag. de 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

Respuesta aceptada

madhan ravi
madhan ravi el 20 de Ag. de 2020
(cumsum(matrix) == 1) .* matrix

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by