Eliminating outer for-loop
显示 更早的评论
Hi,
I have an outer for-loop that I can't manage to get rid of. Code as follows
for t= 1: epochs
... code
for i= 1: n
for j = 1:n
h= exp(-sum(([i j]'- [r c]').^2)/(2*(sigma(t)^2)));
w(:, i, j)= w(:, i, j)+ eta(t)*h*((xiCurrent- w(:, i, j)));
dist(i, j)= sqrt(sum((xiCurrent- w(:, i, j)).^2));
end
end
... code
end
Observe that in the loop over i nothing gets calculated before entering the loop over j, and I would therefore like to eliminate the i-loop, but with no success.
Constraint's are that one xiCurrent are fed per iteration t, and all computations within the t-loop must be finished before t can take a step. An indexed-value of w must be updated before being applied to dist(i, j).
If necessary; n= 30; size(w)= 57000 x 30 x 30; size(xiCurrent)= 57000 x 1 size(dist)= 30 x 30 r and c are constants in the context.
I've used e.g. repmat on xiCurrent, but that gave slower execution than the above code.
I'm grateful for any help, best regards, Daniell
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!