Adding Matlab implementation.