res = trace(x)
| Parameter | Description |
|---|---|
| x | a numeric value: scalar or matrix (double or single), dense or sparse |
| Parameter | Description |
|---|---|
| res | a numeric value: a scalar |
trace(x) computes the trace of x, the sum of the elements along the main diagonal.
Sparse double, single, complex double, and complex single matrices are supported. The result keeps single precision for single inputs.
X = [1 0; 0 3];
Y = trace(X)
X = sparse(single([1 + 2i 0; 0 3]));
Y = trace(X)
| Version | Description |
|---|---|
| 1.0.0 | initial version |
| 2.0.0 | added sparse single and complex single support |