Matlab Code Optimization in calulating 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개)
Alan Weiss
2013년 2월 12일
If you use profile to check which part of your code is taking the most time, I guess you will find that the load operations are your bottleneck. If this guess turns out to be true, then you need to find a way to load just one data file. For example, you could concatenate all your data files into one big matrix, with possibly different lengths that you store in another file. Then just load once, and process the data in chunks.
Alan Weiss
MATLAB mathematical toolbox documentation
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with Optimization Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!