vector optimization
3 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Jan
on 15 Feb 2012
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
See Also
Categories
Find more on Computer Vision with Simulink in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!