Alex's code in matlab.