I have a Matrix A = [1 2 -3; 4 5 -2]. Now without using for loop, I want to filter the array in such a way so that any value less than 0 will return 0. So, the output matrix will be RES = [1 2 0; 4 5 0].
any link / sample code to solve the problem would be greatly appreciated.
RES<0produces a logical array, in this case[false false true; false false true]. Then the notationRES(RES<0)=allows you to set all the values what are true to some value.This is a pretty typical, and useful, Matlab idiom.