For example, given X, a list N of points in R^d, (Nxd matrix). Then X = [x_1;x_2;...;x_N]. I want to compute the distance matrix D (and NxN matrix) between points {x_i}.
If d = 1 I can use bsxfun
:
D = bsxfun(dist,X,X')
Where dist
is defined on scalars by dist = @(x_i,x_j) sqrt( sum((x_i-x_j).^2) )
. For d = 1, dist
takes in two scalars and outputs a scalar, so bsxfun
may be applied.
What I want to do is to have this make since for general d. That is, I need a function like bsxfun that can work when dist takes in two vectors and outputs a scalar.
Does anyone have any ideas?