Borrar filtros
Borrar filtros

remove elements from a matrix

4 visualizaciones (últimos 30 días)
Carlos_conde
Carlos_conde el 17 de Oct. de 2017
Comentada: Carlos_conde el 17 de Oct. de 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?

Respuesta aceptada

Stephen23
Stephen23 el 17 de Oct. de 2017
Editada: Stephen23 el 17 de Oct. de 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

Más respuestas (0)

Categorías

Más información sobre Multidimensional Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by