File Exchange

image thumbnail


version 1.0 (1.59 KB) by

The mean over each diagonal (or anti-diagonal) of a 2D matrix returned in a vector



View License

Efficient and compact code for taking the mean of each diagonal (or anti-diagonal) in a 2D matrix without using a for-loop. Works well for large matrices, and is particularly efficient for tall or wide matrices.

Note that a for-loop implementation with the diag() function might be faster, and have lower memory requirement when applied to close to square matrices (especially if the slow mean() function can be avoided).

However, if the mean across diagonals has to be computed for several matrices of the same size (in a loop), the inlined version of this implementation is typically faster.

Comments and Ratings (0)

MATLAB Release
MATLAB 8.2 (R2013b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video