matlab helper functions and resampling test