how to optimize this nested for loop
Afficher commentaires plus anciens
I have 2 nested loops which do the following:
- Get two rows of a matrix
- Check if indices meet a condition or not
- If they do: calculate xcorr between the two rows and put it into new vector
- Find the index of the maximum value of sub vector and replace element of LAG matrix with this value
I dont know how I can speed this code up by vectorizing or otherwise.
b=size(data,1);
F=size(data,2);
LAG= zeros(b,b);
for i=1:b
for j=1:b
if j>i
x=data(i,:);
y=data(j,:);
d=xcorr(x,y);
d=d(:,F:(2*F)-1);
[M,I] = max(d);
LAG(i,j)=I-1;
d=xcorr(y,x);
d=d(:,F:(2*F)-1);
[M,I] = max(d);
LAG(j,i)=I-1;
end
end
end
2 commentaires
Jan
le 14 Déc 2017
What does "0 down vote favorite" mean?
Walter Roberson
le 17 Déc 2017
It means the question was posted on StackOverflow and copied to here.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Systems of Nonlinear Equations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!