Rewritten to use the interp1() function. Should be faster, and makes for a shorter function.