Software Carpentry's core lessons have a section on Matlab and defensive programming, i.e., "how to tell whether a program is getting the right answer, and how to tell if it’s still getting the right answer as we make changes to it".

lesson:
http://swcarpentry.github.io/matlab-novice-inflammation/06-defensive.html