I am computing a similarity matrix based on Euclidean distance in MATLAB. My code is as follows:
for i=1:N % M,N is the size of the matrix x for whose elements I
There's probably a better way to do it, but the first thing I noticed was that you could cut the runtime in half by exploiting the symmetry D(i,j)==D(i,j)
D(i,j)==D(i,j)
You can also use the function norm(x(:,i)-x(:,j),2)
norm(x(:,i)-x(:,j),2)