The diag(v) function returns a 2D matrix with vector v on diagonal.

Examples

**OML **

>> v=[1 2 3 4]

1 2 3 4

>> diag(v)

1 0 0 0

0 2 0 0

0 0 3 0

0 0 0 4

**Block **

This const block creates a 3-by-3 matrix with the elements 1, 2, 3 on the diagonal. To specify an increment of 0.5, do the following:

A 5-by-5 matrix is created to include the elements 1, 1.5, 2, 2.5, and 3 on the diagonal. To specify an offset of 1, do the following:

Embed expands the matrix to 6-by-6 so that the diagonal vector can be placed above the main diagonal.