parfor loop??? making it faster how?
Show older comments
i have wrote something like this to search for a color reference in live feed from webcam:
opengl hardware
while (nFrame<z)
b = step(vidobj);
n=0;
yb=size(b,1); %rows
zb=size(b,2); %columns
%u=zeros(zb,2); %------------------------------
v=0;
for g=1:1:yb
for h=1:1:zb
if (b(g,h,1)>=rot_min) && (b(g,h,1)<=rot_max)
n=n+1;
v(n,1)=g;
v(n,2)=h;
end
end
end
v;
%end of rot search
so now i want to exploit the core i5 to use all for cores and make the code even more faster...
Answers (2)
Mandar
on 28 Feb 2014
1 vote
1 Comment
Iain
on 28 Feb 2014
1. Put the parfor in the outer loop.
2. You can't use that n in a parfor loop. You may, instead, create "v" to be 2 by yb by zb, and initialised (or set) to NaN when you don't have a valid answer. You can then eliminate the NaNs by
v = reshape(v(~isnan(v),2,[]);
Your problem, however has a faster/simpler solution.
indices = find(b(:,:,1)>= rot_min & b(:,:,1)<=rot_max);
That gets you linear indices to find your qualifying values of b. ind2sub can then be used to return, into a couple of variables (or columns), the rows and column values of the qualifying elements.
Nitin
on 28 Feb 2014
0 votes
Categories
Find more on Loops and Conditional Statements 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!