Avoid allocating an anonymous function

Would you be able to simplify your code and still illustrate your problem? In item 5 in Please read: make it easier to help you this is suggested as one of the ways to make it easier for people to answer your question.