My aim with the loop is to pick out all elements of C that are within range r of rd and range t of td (rd and td are range matrices). Then multiply the elements together and add them to a sum.
This loop is called about a million times and is relatively slow.
Does anyone have an idea of how I can increase the speed of the loop? (I have tried code generation which turned out slower, and parallelism)
for i = 1:indN
D = C(rd(ind(i),:)<r & td(ind(i),:)<t);
if (isempty(D)) D=0; end
gSum = gSum + prod(D);
Profiling gives that D=C(.. line takes 84,7% of the entire run time (the other lines in the loop next to nothing)