vector optimization
3 次查看(过去 30 天)
显示 更早的评论
i have written this code and i wish to use vectorization to the inner if loop. because the program takes a long long time to execute even for a 128x128 image. can someone please provide me with the vector optimization logic for the following code?
for i=1:row
for j=i+1:row
if C(i,g)==C(j,g)
P2(C(i,g+1):C(i,g+1)+in-1, C(i,g+2):C(i,g+2)+in-1)=0;
P2(C(j,g+1):C(j,g+1)+in-1, C(j,g+2):C(j,g+2)+in-1)=0;
end
end
end
回答(1 个)
Jan
2012-2-15
Not a vectorization, but at least no repeated calculations in the inner loop:
for i=1:row
C_ig = C(i, g);
a = false;
for j=i+1:row
if C_ig == C(j,g)
a = true;
P2(C(j,g+1):C(j,g+1)+in-1, C(j,g+2):C(j,g+2)+in-1) = 0;
end
end
if a
P2(C(i,g+1):C(i,g+1)+in-1, C(i,g+2):C(i,g+2)+in-1) = 0;
end
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Computer Vision with Simulink 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!