Matlab version with linear interpolation