How dist function works??
25 views (last 30 days)
Christiaan on 9 Mar 2015
Edited: Christiaan on 9 Mar 2015
The dist function is a 'Euclidean distance weight function' which applies weights to an input to get weighted inputs. At your example:
W is the (random) weight matrix. P is the input vector Z is the weighted input
If you type in the matlab prompt 'edit dist.apply' you find the formula behind this function. For your example, the weighted matrix is subtracted from the transposed and copied vector. Now it is squared and then the square root is taken. This is how the Euclidian norm is defined Norm = square((a-b)^2)
I have copied the code and made the example simpler to understand in the code below better:
clc;clear all;close all;
w=[1 1 2;1 1 1;1 2 1;1 1 1]
% dist function
S = size(w,1);
Q = size(p,2);
z2 = zeros(S,Q);
p = p';
copies = zeros(1,S);
z2(:,q) = sum((w-p(q+copies,:)).^2,2);
w = w';
copies = zeros(1,Q);
z2(i,:) = sum((w(:,i+copies)-p).^2,1);
z2 = sqrt(z2)
Here z1 and z2 should give the same answer.
I hope this makes it clearer.
Kind regards, Christiaan