> For the complete documentation index, see [llms.txt](https://nelson-9.gitbook.io/Nelson/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nelson-9.gitbook.io/Nelson/markdown/en/constructors_functions/diag.md).

# diag

Get diagonal elements of matrix or create diagonal matrix.

## 📝 Syntax

* D = diag(V)
* X = diag(A)
* D = diag(V, k)
* X = diag(A, k)

## 📥 Input argument

* V - Diagonal elements
* A - Input matrix

## 📤 Output argument

* D - vector
* X - matrix

## 📄 Description

diag returns diagonal elements of matrix or create diagonal matrix.

## 💡 Example

```matlab
diag(eye(3))
diag(diag(eye(3)))
```

## 🔗 See also

[ones](/Nelson/markdown/en/constructors_functions/ones.md).

## 🕔 History

| Version | 📄 Description  |
| ------- | --------------- |
| 1.0.0   | initial version |
