MATLAB: Generating matrix with ones and zeros

matrixmatrix array

Hello guys
Can you please help generating a matrix with size of (RXC) = (4X12)
Where, here the 3 ones are in first row then all zeros. The second row starts with 3 zeros then three ones then zeros to the end. This repeates for all rows. But the most improtant thing that I need to generate such pattern for any number of rows and columns. For example, for (4X8), it should look like
two ones then zeros. The seocnd row starts with two zeros then two ones then zeros to the end.
Many thanks for your help!

Best Answer

Use the blkdiag function:
v = ones(1,3);
x = blkdiag(v,v,v,v)
.