From: Gumah on
hi all
how to get the Euclidean distance between two vectors using dist
function
lets say we have
a=[1 2 3]
b=[4 5 6]
how can get C=dist(a,b) ?? I tried to use dist but got this error:
??? Error using ==> dist>apply at 118
Inner matrix dimensions do not match.

Error in ==> boiler_weight at 38
result = apply(a,b,c);

Error in ==> dist at 90
boiler_weight
From: Walter Roberson on
Gumah wrote:

> how to get the Euclidean distance between two vectors using dist
> function
> lets say we have
> a=[1 2 3]
> b=[4 5 6]
> how can get C=dist(a,b) ?? I tried to use dist but got this error:
> ??? Error using ==> dist>apply at 118
> Inner matrix dimensions do not match.
>
> Error in ==> boiler_weight at 38
> result = apply(a,b,c);
>
> Error in ==> dist at 90
> boiler_weight

Which dist() function are you using? I see there is one for neural nets,
but for it if the first parameter is not a string then the first
parameter must be a square array of weights and the second parameter is
the vectors. I do not immediately find dist() in the other toolboxes,
and it is not part of basic Matlab.

But what do you mean by the "Euclidean distance between two vectors" ?
Vectors have magnitude and direction but not inherent position. Perhaps
you mean sum((a-b).^2) ?
From: ImageAnalyst on
On May 24, 8:43 pm, Walter Roberson <rober...(a)hushmail.com> wrote:
> Perhaps you mean sum((a-b).^2) ?
--------------------------------------------------
With the addition of the square root, that would be my guess.
EuclideanDistance = sqrt(sum((a-b).^2))

From: Stephen Vanreusel on

Hi,
Alternatively, you can just use the NORM function in standard MATLAB:

>> norm(a-b)

ans =
5.1962

>> sqrt(sum((a-b).^2))

ans =
5.1962

ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <5d8655c3-003d-4560-a4b0-5702d3db3ab2(a)y12g2000vbg.googlegroups.com>...
> On May 24, 8:43 pm, Walter Roberson <rober...(a)hushmail.com> wrote:
> > Perhaps you mean sum((a-b).^2) ?
> --------------------------------------------------
> With the addition of the square root, that would be my guess.
> EuclideanDistance = sqrt(sum((a-b).^2))