MATLAB: Change of whole row in matrix

cell arraymatrix manipulation

Hello, I have matrix:
32.5000 32.5000 36.0000 37.0000
112.5000 60.5000 34.0000 35.0000
83.5000 152.5000 51.0000 52.0000
-11.0000 -19.5000 22.0000 39.0000
I want to check every element of it and if any element value is < 0 then I want to whole row be zeros. So I want this matrix:
32.5000 32.5000 36.0000 37.0000
112.5000 60.5000 34.0000 35.0000
83.5000 152.5000 51.0000 52.0000
0 0 0 0
Is it possible to do it?

Best Answer

  • YourMatrix( any(YourMatrix<0, 2), :) = 0;