Euclidean distance dist function

Hi, I tried to calculate euclidean distance between two vectors, their dimensions are different, one is somethingx12 another is somethingx12, but these two somethings are different. im calculating the dtw - dinamic time warping, and i wrote the line dist(s(i,:),t(j,:)); but matlab tells me that there is an error. that ":" in this line means that i want to calculate euclidean distance between line "i" vector from s matrix(which has 12 columns) and line "j" vector from t matrix(which has 12 columns as well), and there is an error, can You find any solution? i got an error like that: "Error in ==> dist>apply at 244 z(i,:) = sum((w(:,i+copies)-p).^2,1);
Error in ==> dist at 127 out1 = apply(in1,in2,in3);
Error in ==> dtw at 18 cost = dist(s(i,:),t(j,:);
dtw is my function of dynamic time warping, dist is calculatin euclidean distance between two vectors, 1x12, something is wrong here and i cant figure it out...

6 commentaires

Image Analyst
Image Analyst le 26 Sep 2012
Can you give an example of how you'd want the math to go? Maybe code it up in a for loop or something so we can see what calculations you think are valid.
Nesrider da Silva
Nesrider da Silva le 26 Sep 2012
Modifié(e) : Nesrider da Silva le 26 Sep 2012
function d=dtw(s,t)
n=size(s,1);
m=size(t,1);
cost=0;
DTW=zeros(n,m);
dtw=0;
d=0;
for z=1:12
for i=1:m
DTW(1,i)=inf;
end
for j=1:n;
DTW(j,1)=inf;
end
DTW(1,1)=0;
for i=2:n
for j=2:m
cost= dist(s(i,z),t(j,z));%the problem is here, when it gets one vector 60x12 and another 70x12, but it should calculate it properly...
c=min(DTW(i-1,j),DTW(i,(j-1)));
minimum=min(c,DTW((i-1),(j-1)));
DTW(i,j)=cost+minimum;
end
end
Wynik=DTW(size(DTW,1),size(DTW,2));
d=d+Wynik;
end
end
Star Strider
Star Strider le 26 Sep 2012
Please post your code for your dist() function. Note also that dist() is part of the Neural Network Toolbox, and if you have that Toolbox you are not calling dist() correctly. I suggest that for a start, you rename your function dtwdist or something to prevent the name conflict.
Nesrider da Silva
Nesrider da Silva le 27 Sep 2012
i use a function from the matlab library, dist() is a function which calculate the euclidean distance between two points, vectors, matrix etc. You can find it in matlab, help dist.
Image Analyst
Image Analyst le 27 Sep 2012
No we can't. That is not one of the base MATLAB functions. Type "which dist" on the command line and tell us what it says. Maybe you're meant norm().
Star Strider
Star Strider le 28 Sep 2012
... or pdist2.

Connectez-vous pour commenter.

 Réponse acceptée

Greg Heath
Greg Heath le 27 Sep 2012

1 vote

You used dist incorrectly.
The input is a single I x N matrix consisting of N I-dimensional column vectors.
The output is a single symmetric N x N matrix consiting of N*(N-1) unique distances.
Hope this helps.
Thank you for formally accepting my answer.
Greg

Plus de réponses (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by