MATLAB: Replace elements in a SxS matrix with zero, in each column but in different rows

columnreplacerowzeros

Hi people,
I know how to simply replace elements with zero, but I'm stuck with this problem. I have a matrix 2108×62 and I need to replace elements in column #1 and row 1-34 by zero, then in column #2 but row 35-68, then column #3 but row 69-102 etc to the end of column 62 and row 2075-2108.
Best,
Miroslav

Best Answer

This is simple using either the FEX submission expand:
>> mat = randi(9,2108,62);
>> idx = expand(eye(62)==1,[2108/62,1]);
>> mat(idx) = 0;
or for newer MATLAB versions repelem:
>> idx = repelem(eye(62)==1,2108/62,1);