필터 지우기
필터 지우기

Matlab Code Optimization in calulating euclidean distance between vectors

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

Alan Weiss
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
  댓글 수: 1
.. Vamshi
.. Vamshi 2013년 2월 13일
편집: .. Vamshi 2013년 2월 13일
I can load them at once in the beginning so no problem there. The problem is I am calculating euclidean distance of each vector with one another which executes 135x135 (if N=135). I want to cut the time in computation here. So help me in this regard.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by