remove elements from a matrix

4 vues (au cours des 30 derniers jours)
Carlos_conde
Carlos_conde le 17 Oct 2017
Commenté : Carlos_conde le 17 Oct 2017
Hello,
I have a matrix 1080x840 filled with 0 and 1, like:
[1 1 1 1 1 1 0 0 0 0 0 ;
1 1 1 1 1 1 1 1 0 0 0 1;
1 1 1 1 1 0 0 0 1 0 0 1;
1 1 1 1 1 1 0 0 0 1 0 1]
where a "zero' appears I would like to change the ones located in the right of the zero to zero. So, the new matrix would be:
[1 1 1 1 1 1 0 0 0 0 0;
1 1 1 1 1 1 1 1 0 0 0 0;
1 1 1 1 1 0 0 0 0 0 0 0;
1 1 1 1 1 1 0 0 0 0 0 0]
How can I do that?

Réponse acceptée

Stephen23
Stephen23 le 17 Oct 2017
Modifié(e) : Stephen23 le 17 Oct 2017
Very simply using cumprod:
>> M = [1,1,1,1,1,1,0,0,0,0,0,0;1,1,1,1,1,1,1,1,0,0,0,1;1,1,1,1,1,0,0,0,1,0,0,1;1,1,1,1,1,1,0,0,0,1,0,1]
M =
1 1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 1 1 1 0 0 0 1
1 1 1 1 1 0 0 0 1 0 0 1
1 1 1 1 1 1 0 0 0 1 0 1
>> cumprod(M,2)
ans =
1 1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 1 1 1 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0 0
1 1 1 1 1 1 0 0 0 0 0 0
  1 commentaire
Carlos_conde
Carlos_conde le 17 Oct 2017
Thanks a lot

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by