Here are the MATLAB and R implementations of the MERGE algorithm: