Watch this Author's files
The latest submission includes the function written in the C programming language, as well as a MEX implementation, thus providing significant speed and memory enhancements.
Does the trick!
Very useful and efficient functions. Thanks to the willing and gentle author for the prompt and clear help.