I know I can pass all the element of the matrix and do that.
but maybe there is another option.
I want to do:
mat1 = mat2 * mat1;
each element in mat1 that become to negative or bigger than 255, I want to leave the previous element.
for example (the result is not true, this is only for the example):
mat1 = [10 25 12
33 7 163
232 13 77]
mat2 = [-1 2 -3
4 -5 6
-7 -8 9]
asume mat1 = mat2 * mat1 gives:
mat1 = [-77.32 59 298
0 -33 12
-600 256 80]
so I want to repair mat1 to be:
mat1 = [10 59 12
0 7 12
232 13 80]
If i understand you correctly, you have a matrix multiplication
Best is to store the matrix multiplication result in a third matrix
With
you a matrix with ones where you want to replace and zero where not. Apply this index to replace the values in mat3 with the values of mat1
The result is a matrix in which every element smaller than 0 or bigger than 255 has been replaced with the value of mat1.