Code covered by the BSD License  

Highlights from
meanDiag

Be the first to rate this file! 4 Downloads (last 30 days) File Size: 1.59 KB File ID: #44165

meanDiag

by

 

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

| Watch this File

File Information
Description

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.

Required Products MATLAB
MATLAB release MATLAB 8.2 (R2013b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.

Contact us