Optimize MATLAB code (nested for loop to compute similarity matrix)

前端 未结 4 900
小蘑菇
小蘑菇 2021-02-11 01:54

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         


        
4条回答
  •  再見小時候
    2021-02-11 02:37

    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)

    You can also use the function norm(x(:,i)-x(:,j),2)

提交回复
热议问题