diag() command or function gives diagonal elements or creates a diagonal matrix, after reading this MATLAB diagonal matrix topic, you will know the theory and examples.
Syntax:
diag(n)
- n can be a vector or matrix.
Example: To create a 2×2 diagonal matrix having diagonal elements as 1 and 2.
Output:
ans =
1 0
0 2
Example: To create a column vector of diagonal elements from the given Matrix.
Output:
n =
1 2 3
3 2 1
4 5 1
v =
1
2
1
Related Topics
MATLAB matrix inverseinv( ) command or function gives the inverse of a matrix, after reading this MATLAB…
MATLAB onesThis command creates an array of all ones, after reading this MATLAB ones topic, you…
MATLAB eyeThis command creates an Identity matrix, after reading this MATLAB eye topic, you will know the…
MATLAB lengthlength() command or function gives the number of elements in a vector or length of…
MATLAB sortsort( ) command or function arranges vector or matrix or array elements in ascending order, after reading…