Euclidean distance between vectors
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
The following code is taking a lot of time for execution say if N=135. How can I make it faster. Is there an alternative to calculate the euclidean distance between the vectors.
FVCompare= zeros(N,N); file = 'FV';
for i=1:N
sname = strcat(file,int2str(i));
sfile = strcat('FeatureVectors\',sname);
srcfile = strcat(sfile,'.mat');
for count=1:N
dname = strcat(file,int2str(count));
dfile = strcat('FeatureVectors\',dname);
destfile = strcat(dfile,'.mat');
Vec1 = load (srcfile); %loads FeatureVector-1
Vec2 = load (destfile); %loads FeatureVectors to be compared
var1 = struct2cell(Vec1);
fv1=var1{:};
var2 = struct2cell(Vec2);
fv2=var2{:};
%Finding Euclidean Distance
R = norm(fv1-fv2);
FVCompare(i,count) = R;
end
end
0 Kommentare
Antworten (1)
Walter Roberson
am 23 Feb. 2013
You can move the loading of srcfile to before the "for count" loop, as it is not going to change as count changes.
As the source file list is the same as the destination file list, comparing source 5 to destination 8 is going to give you the same result as comparing source 8 to destination 5. Therefore you only need to compare source "i" to destinations "count" when count >= i, and you can fill in the rest by symmetry.
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!