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!