Skip to content


Trace of a matrix


  • A should be a square matrix.
  • It returns the trace of A, i.e., sum(diag(A)).
  • A can be a numeric, logical, or character array, which is converted to a numeric array before computing the trace.
  • If A is empty, it returns 0.