Euclidean distance between vectors
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Mathematics and Optimization についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!