Delete all values in a row after the first value
Afficher commentaires plus anciens
Hi everyone
I have a matrix with 3000 rows and 4 columns. the values in the matrix are just one and zero. The sum of each row can just be one. In some rows the sum is 2. What I want now is to delete all 1 after the first 1. So in my matrix in each row I just want the first vaue 1 and all the following values in this matrix should be 0.
For example: row number 345: 0001000 1 0000 change to 0001000 0 0000
thank you for your help.
Réponse acceptée
Plus de réponses (1)
Walter Roberson
le 6 Oct 2016
Modifié(e) : Walter Roberson
le 6 Oct 2016
B = cumsum(~cumprod(~A,2), 2) <= 1;
If I worked it out properly as I fall asleep...
Catégories
En savoir plus sur Operators and Elementary Operations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!