Hi,
I'm tring to calculate the standard deviation of a vector of doubles (called A). Now I have a function called StDev that will do this. However, the first few elements of vector A are zero and I need to remove these. To do this I create a sub-array and then pass this to my StDev function as follows:
std::vector<double> Array(find_if(Data.begin(), Data.end(), std::bind1st (std::not_equal_to<double>(), 0.0)), Data.end());
double standard_deviation = StDev(Array);
Is there a way of doing this without having to create the vector 'Array' which is only used once. Can I somehow pass the required sub-array directly?
Thanks!