functional matlab version? runs now, just need to do the comparisons on proper grid