MATLAB: How to replace the values from a diagonal submatrix

replace diagonalreplace submatrixreplace valuesubmatrix

Let us suppose I have a square matrix (6×6 for example). I need to raplace the diagonal square submatrices (2×2) by zeros:
Original matrix:
[12 89 64 125 98 856
15 56 36 874 320 523
6 54 54 692 703 147
8 128 65 632 904 236
98 78 74 541 106 569
5 69 71 446 205 832]
Final matrix:
[0 0 64 125 98 856
0 0 36 874 320 523
6 54 0 0 703 147
8 128 0 0 904 236
98 78 74 541 0 0
5 69 71 446 0 0]

Best Answer

>> A=rand(6)
A =
0.8147 0.2785 0.9572 0.7922 0.6787 0.7060
0.9058 0.5469 0.4854 0.9595 0.7577 0.0318
0.1270 0.9575 0.8003 0.6557 0.7431 0.2769
0.9134 0.9649 0.1419 0.0357 0.3922 0.0462
0.6324 0.1576 0.4218 0.8491 0.6555 0.0971
0.0975 0.9706 0.9157 0.9340 0.1712 0.8235
>> A(logical(kron(eye(length(A)/2),ones(2))))=0
A =
0 0 0.9572 0.7922 0.6787 0.7060
0 0 0.4854 0.9595 0.7577 0.0318
0.1270 0.9575 0 0 0.7431 0.2769
0.9134 0.9649 0 0 0.3922 0.0462
0.6324 0.1576 0.4218 0.8491 0 0
0.0975 0.9706 0.9157 0.9340 0 0
>>