Self contained MATLAB script for testing
Fixed a soft bug in the called function. All seems to be working now