MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by Eimear Nolan
on 25 Apr 2013

Hi! I have two matrices A(identity matrix) and B and I want to make a matrix C where B is on the diagonal for the entire matrix and A is on the sub and super diagonal on the entire matrix.I have tried using the kron command but I want to be able to see separate blocks of the matrices in C. As in I should be able to see a 2 diagonals of all ones in my C matrix. Any help would be appreciated!

*No products are associated with this question.*

Answer by Ahmed A. Selman
on 25 Apr 2013

Use the command (diag) for creating a (main) diagonal matrix from a vector A, and the command (spdiags) to create sub- and super-diagonal. Kronecker function does not make diagonal matrices, it rather finds the product of two tensors.

## 1 Comment

## the cyclist (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/73604#comment_145556

Your question would be easier to understand if you made a small example.