diag

Linear Algebra

Create diagonal matrix from vector, or extract diagonal.

Syntax

diag(v)
diag(A)

Examples

diag([1, 2, 3])
▶ Run
diag([1 2; 3 4])
▶ Run

Try SimLab — Free MATLAB® Alternative

466 functions. Runs in your browser. No install.

Open SimLab

Stay Updated

Get notified about new simulations and tools. We send 1-2 emails per month.