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
댓글 수: 2
답변 (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!