I have two matrices of size trainv = 60000X784 and testv = 10000X784. How is it possible to efficiently compute the Euclidean distance between each vector in testv and trainv? It takes quite a long time to do it in this way:
 for j = 1:60000
    for i = 1:10000
        d(i,j) = norm((trainv(i,:)-testv(j,:)),2);
        %d(i,j) = bsxfun(@plus,dot(trainv(i,:),trainv(i,:),2),dot(testv(j,:),testv(j,:),2)')-2*(trainv(i,:)*testv(j,:)');
    end
end