I'm having trouble trying to visualize writing code for my problem because I'm so used to using pdist
.
What I would like to do is to compute all non-absolute distances of a vector. so that my metric is just (x-y), where x and y are two values in my vector.
Typically, I would just do the following:
squareform(pdist(X(:,i))
However this would return the EUCLIDEAN distance, not my distance. Is there a way to do this with pdist? Or maybe is there a different method?
Here's an example of what I'm trying to compute.
For X=[1,2,3;4,5,6;7,8,9]
For the FIRST matrix, the matrix of all differences of the elements in the first column, we should have
D=[(1-1), (1-4), (1-7); (4-1), (4-4), (4-7); (7-1), (7-4), (7-7)]
or
D=[0,-3,-6;3,0,-3;6,3,0]
distfun
to do what you need. Sorry for the mistake earlier. It neededbsxfun
andsum
. Tested this time. – chappjcX=[1,2,3;4,5,6;7,8,9]
giving the matrixD=[0,-3,-6;3,0,-3;6,3,0]
, I posted the loop to do that. note that you can't do this withpdist
since this is not symmetric. – chappjc