remove elements from a matrix

4 Ansichten (letzte 30 Tage)
Carlos_conde
Carlos_conde am 17 Okt. 2017
Kommentiert: Carlos_conde am 17 Okt. 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?

Akzeptierte Antwort

Stephen23
Stephen23 am 17 Okt. 2017
Bearbeitet: Stephen23 am 17 Okt. 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

Weitere Antworten (0)

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by