meanDiag

The mean over each diagonal (or anti-diagonal) of a 2D matrix returned in a vector
185 Downloads
Updated 4 Nov 2013

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.

Cite As

Marcus Björk (2024). meanDiag (https://www.mathworks.com/matlabcentral/fileexchange/44165-meandiag), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2013b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Operating on Diagonal Matrices in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0.0