How to get the average value from multiple line traces

In your loop, put the distances in an array

and then afterwards