Bins an N-dimensional MATLAB array by grouping adjacent elements along each dimension according to binVector, then either summing or averaging within each bin. The implementation truncates dimensions to the largest compatible size before binning and minimizes costly permutations by focusing one dimension at a time.
Gomez-Sanchez, A. (2025). binning function. GitHub repository. https://github.com/LovelaceSquare/binning Version 2.1.