Borrar filtros
Borrar filtros

Matlab Code Optimization in calulating euclidean distance between vectors

1 visualización (últimos 30 días)
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

Respuestas (1)

Alan Weiss
Alan Weiss el 12 de Feb. de 2013
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 comentario
.. Vamshi
.. Vamshi el 13 de Feb. de 2013
Editada: .. Vamshi el 13 de Feb. de 2013
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Linear Algebra en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by