Fixing chebsnake in new version of Matlab

Fixes as suggested by @nickhale.

This works both on 2014a and 2014b on my machine (Mac). The nan checking did not seem to be necessary.

Would be good if someone else could test this as well.