1 diag(diag(D)) ans = 1 0 0 0 1 0 0 0 1 repmat(D,1,3) ans = Columns 1 through 8 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 Column 9 |