Solved - I think

I think I have solved it with a bit of added code. Still need to test if it gives the same result as the original code (ported from MC/TS), but it does not give inconsistent errors any longer and can plot values which appear correct from initial appearances.

Here is what I had to add, removing the series function from inside the for loop but still inside the if conditional. Rather than loop I simply manually populate and increment.

This is defined outside the conditional:
q = series();

this is inside the conditional:
q[hcount] = (qqtot/len);
hcount +=1;
qqtot = 0;