Processing random matrices
My best guess given the information:
You are doing some expensive ismember operations. You can try to get rid of them by tracking Done in a different way.

Perhaps you can use a more efficent way to do it in the same location, or perhaps you need to move it inside the loop and do it in a very cheap way there.