Extended Capabilities

C/C++ Code GenerationGenerate C and C++ code using MATLAB® Coder™.

For variable-size inputs that are variable-length
vectors (1-by-: or :-by-1), diag:

Treats the input as a vector input

Returns a matrix with the given vector along the specified
diagonal

For variable-size inputs that are not variable-length
vectors, diag:

Treats the input as a matrix

Does not support inputs that are vectors at run time

Returns a variable-length vector

If the input is variable-size (:m-by-:n) and has shape 0-by-0
at run time, then the output is 0-by-1 not 0-by-0. However, if the
input is a constant size 0-by-0, then the output is [].

For variable-size inputs that are not variable-length
vectors (1-by-: or :-by-1), diag treats the input
as a matrix from which to extract a diagonal vector. This behavior
occurs even if the input array is a vector at run time. To force diag to
build a matrix from variable-size inputs that are not 1-by-: or :-by-1,
use: