calculate distance using the below equation
显示 更早的评论
i have 2 variables, dataMatrix and queryMatrix..... dataMatrix contains 245 rows and 38 column values...... and queryMatrix contains 1 row and 38 column values...... i calculate the euclidean distance and sort the distances in ascending order as below.....
for w=1:245
dist = sum((repmat(queryMatrix(w,:),245,1)-dataMatrix).^2,2);
[sortval sortpos] = sort(dist,'ascend');
neighborIds(w,:) = sortpos(1:k);
neighborDistances(w,:) = sqrt(sortval(1:k));
end
instead of euclidean distance i want to use the distance formula in the below link.....
but i dont know to write the equation in matlab...... please can someone convert that equation to matlab..... it would be great help to me..... please do reply......
1 个评论
采纳的回答
更多回答(1 个)
Andrei Bobrov
2013-4-11
编辑:Andrei Bobrov
2013-4-11
dataMatrix = randi([-10,10],10,5);
queryMatrix = randi([-10 10],1,5);
d = bsxfun(@(x,y)abs(x - y)./(abs(x) + abs(y)),...
dataMatrix,permute(queryMatrix,[3 2 1]));
d = sort(squeeze(sum(d,2)));
类别
在 帮助中心 和 File Exchange 中查找有关 Common Weakness Enumeration (CWE) 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!