MATLAB: Special matrix with zeros and ones

ones and zeros matrix

Hello Everyone,
I have a special matrix and can not create it in faster way
The example of a matrix is as follows:
m=[1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1]
I can build it up by using ones and zeros, but it will take me a long time to do that, specially when I have a very big matrix.
Thanks in advance.

Best Answer

Are you looking for kron?
kron(eye(4), ones(1, 4))
kron is not efficient. This might be faster, but less nice:
n = 4;
ind = repmat(n, 1, n*n-1);
ind(n:n:n*n-1) = n + 1;
M = zeros(n, n*n);
M(cumsum([1, ind])) = 1;