how to optimize this nested for loop
显示 更早的评论
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 个评论
Jan
2017-12-14
What does "0 down vote favorite" mean?
Walter Roberson
2017-12-17
It means the question was posted on StackOverflow and copied to here.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Systems of Nonlinear Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!