필터 지우기
필터 지우기

Euclidean distance between vectors

조회 수: 1 (최근 30일)
.. Vamshi
.. Vamshi 2013년 2월 23일
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

답변 (1개)

Walter Roberson
Walter Roberson 2013년 2월 23일
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.

카테고리

Help CenterFile Exchange에서 Mathematics and Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by