parfor loop??? making it faster how?
Afficher commentaires plus anciens
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...
Réponses (2)
Mandar
le 28 Fév 2014
1 vote
1 commentaire
Iain
le 28 Fév 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
le 28 Fév 2014
0 votes
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!