Questions tagged «vectorization»

2
倍频程:计算两个向量矩阵之间的距离
假设我有两个分别代表N,M个2d向量的矩阵Nx2,Mx2。有没有一种简单而又好的方法来计算每个向量对(n,m)之间的距离? 简单但低效的方法当然是: d = zeros(N, M); for i = 1:N, for j = 1:M, d(i,j) = norm(n(i,:) - m(j,:)); endfor; endfor; 我找到的最接近的答案是bsxfun,用法如下: bsxfun(inline("x-y"),[1,2,3,4],[3;4;5;6]) ans = -2 -1 0 1 -3 -2 -1 0 -4 -3 -2 -1 -5 -4 -3 -2

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.