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......
No products are associated with this question.
Assuming queryMatrix and dataMatrix are both 245x38, the whole thing can be done without loops,
num = abs(bsxfun(@minus,d,q)); den = bsxfun(@plus,abs(d),abs(q));
[sortval sortpos] = sort(dist); neighborIds = sortpos(1:k,:); neighborDistances = sqrt(sortval(1:k,:));