edited your "pairs.m" file. noticed that when you use the least-squares sum method, the matrix you get is symmetric. therefore, I calculated the lower triangular only, 'nan' on diagonals, and copied over the transpose cell pair. When I set ut very low, this speedup really shows:
for i=1:n2
for j=1:(i-1)
Qdist(i,j)=sum((x(:,i)-x(:,j)).^2);
Qdist(j,i)=Qdist(i,j);
end
Qdist(i,i)=nan;
end
last note: i don't think you use pairs(:,2)=m'; anywhere in the parent scripts, maybe you could eliminate it.