matlab script to generate correct merges