https://www.mathworks.com/matlabcentral/answers/181820-how-dist-function-works
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;
p=[1;2;3] w=[1 1 2;1 1 1;1 2 1;1 1 1] z1=dist(w,p)
% dist function S = size(w,1); Q = size(p,2); z2 = zeros(S,Q); if (Q<S) p = p'; copies = zeros(1,S); for q=1:Q z2(:,q) = sum((w-p(q+copies,:)).^2,2); end else w = w'; copies = zeros(1,Q); for i=1:S z2(i,:) = sum((w(:,i+copies)-p).^2,1); end end z2 = sqrt(z2)
Here z1 and z2 should give the same answer.
I hope this makes it clearer.
Kind regards, Christiaan
'Matlab ' 카테고리의 다른 글
graycomatrix가 [0,255] 사이의 이미지 입력 시 [0,8]으로 변환되는 이유 (0) | 2017.02.03 |
---|---|
Running MATLAB function from Java (0) | 2017.02.01 |
윈도우 octave 옥타브 설치 (0) | 2017.01.03 |
Binary image convex hull (0) | 2016.11.02 |
How do I change the MATLAB User Interface from Korean to English in R2014a and later? (0) | 2016.10.06 |