MATLAB: Reallocate values in matrix to even the values

matrix and reallocation

I have this original traffic matrix
Y = [0.00 10.0 10.0 10.0;
10.0 0.00 10.0 10.0;
10.0 10.0 0.00 10.0;
10.0 10.0 10.0 0.00;]
And when one of them becomes 0, for example,
Y = [0.00 0.00 10.0 10.0;
0.00 0.00 10.0 10.0;
10.0 10.0 0.00 10.0;
10.0 10.0 10.0 0.00;]
I want to guarantee that the 0.00 is always 5.00
Y = [0.00 5.00 10.0 10.0;
5.00 0.00 10.0 10.0;
10.0 10.0 0.00 10.0;
10.0 10.0 10.0 0.00;]
but because of that some of the values decreases
Y = [0.00 5.00 5.00 10.0;
5.00 0.00 10.0 5.00;
5.00 10.0 0.00 10.0;
10.0 5.00 10.0 0.00;]
I was wondering if there is code to do this efficiently for this part? The second part will be, can I even the values further? For example below
Y = [0.00 5.00 7.50 7.50;
5.00 0.00 10.0 5.00;
7.50 10.0 0.00 7.50;
7.50 5.00 7.50 0.00;]

Best Answer

n = size(Y);
lo = ~eye(n);
Y(lo) = max(Y(lo),5);