Thanks, Bernhard, that's good advice. I'll look into "namespace" and "nlimt".
I do not believe "findpeaks" was a basic built-in function when I first created my function (back in Matlab 6.5), but I agree that I should change the name of my function to avoid the conflict.
Great and very useful work!
The only drawbacks are that the function findpeaks already comes with MATLAB and you make heavy use of global variables (can lead to bad side effects when used in conjunction with other code).
Consider using a namespace or rename the function and generally check mlint results (this should also improve performance).