Direct convert from the MATLAB code.