mat_vec=zeros(100,10000);
点积是dot(xi, xj)
distanceFunction = @(xi, xj)dot(xi, xj)
mat_dist=pdist(mat_vec, distanceFunction)
错误信息,如
distanceFunction =
function_handle with value:
@(xi,xj)dot(xi,xj)
Error using pdist
Error evaluating distance function '@(xi,xj)dot(xi,xj)'.
Error in Task1_lab404_02 (line 45)
mat_dist=pdist(mat_vec, distanceFunction)
Caused by:
Error using dot
A and B must be same size.
1条答案
按热度按时间q0qdq0h21#
来自
pdist
documentation(重点是我的):距离函数的形式为
function D2 = distfun(ZI,ZJ)
哪里
ZI
是包含单个观测的1
xn
向量。ZJ
是包含多个观测值的m2
×n
矩阵。该函数必须接受具有任意数量观测值的矩阵ZJ
。因此,您需要在第二个输入上定义函数矢量化。对于点阵产品来说,这很容易做到:
但是请注意,这不是一个真正的距离函数,因为对于复数输入,
distanceFunction(a,b)
不等于distanceFunction(b,a)
。pdist
只会给出其中一个结果。