meanDiag
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
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 |