how to optimize this nested for loop
Show older comments
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 Comments
Jan
on 14 Dec 2017
What does "0 down vote favorite" mean?
Walter Roberson
on 17 Dec 2017
It means the question was posted on StackOverflow and copied to here.
Accepted Answer
More Answers (0)
Categories
Find more on Systems of Nonlinear Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!