How to vectorize this code to eliminate nested For loops
显示 更早的评论
Would like to know how this code be vectorized:
for y=1:rows
for x=1:cols
if (segMat(y,x) == 255)
Energy(y,x) = Energy(y,x) + motionMap(y,x);
end
end
for y=1:rows
for x=1:cols
delta(y,x) = kronDel(255, segMat(y,x));
end
end
The kronDel function acts like the Kronecker delta.
2 个评论
Rik
2018-9-4
Is segMat a function or an array? The second set of loops could be replaced with a call to arrayfun, but this is not always a speed improvement.
Jae Min Lee
2018-9-4
编辑:Jae Min Lee
2018-9-4
采纳的回答
更多回答(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!