MATLAB: I am trying to find the euclidean distance of 2 vector with different sizes

euclidean distanceMATLABmatrixes

T =
5.1000 3.5000 1.4000 0.2000
6.4000 3.2000 4.5000 1.5000
5.4000 3.4000 1.7000 0.2000
5.7000 2.8000 4.5000 1.3000
5.7000 4.4000 1.5000 0.4000
5.6000 2.9000 3.6000 1.3000
X =
5.5000 3.8000 1.9000 0.4000
6.4000 2.9000 4.3000 1.3000
4.3000 3.0000 1.1000 0.1000
5.4000 3.0000 4.5000 1.5000
I want to use this method to find euclidean distance for each row of T and X in such a way use the each row of X to T(6,4)
for example first row will be = sqrt ((5.5 – 5.1)^2 + ((3.5 – 3.8)^2 + ((1.4 – 1.9)^2 + 0.2 -0.4)^2………………..first row to the 24th row ( the number of row to obtain is 24)
Kindly get back to me thank

Best Answer

I'm also not clear on what you're asking. If you want to find the euclidean distance between each row of T and each row of X, then this is easily done:
T = [
5.1000 3.5000 1.4000 0.2000
6.4000 3.2000 4.5000 1.5000
5.4000 3.4000 1.7000 0.2000
5.7000 2.8000 4.5000 1.3000
5.7000 4.4000 1.5000 0.4000
5.6000 2.9000 3.6000 1.3000];
X = [
5.5000 3.8000 1.9000 0.4000
6.4000 2.9000 4.3000 1.3000
4.3000 3.0000 1.1000 0.1000
5.4000 3.0000 4.5000 1.5000];
distance = sqrt(sum((permute(T, [1 3 2]) - permute(X, [3 1 2])) .^ 2, 3))
distance(r, c) is then the distance between T(r, :) and X(c, :)