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

前端 未结 4 1934
不思量自难忘°
不思量自难忘° 2021-02-11 02:02

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)

提交回复
热议问题