Watch this Author's files
Must simpler would be:
[unique_sorted,i,j] = unique(A,'rows','first'); B = A(sort(i),:);
Contact us at files@mathworks.com