How do i take the average over each certain length of a vector?

2 views (last 30 days)
I have a vector of depth from 500 until 4000 ft. I have also the value of a pressure for each depth. for example from 100 until 300. i want to take the average the pressure values over 20 ft (I want to take average in the length of each 20 ft)?
Would you please help me with that?
Thanks

Answers (1)

Walter Roberson
Walter Roberson on 30 Dec 2015
T = cumsum(data);
average = diff(T(1:20:end))/20
or
average = mean(reshape(data,20,[]))
The second of those requires that the data be an exact multiple of 20 in length.

Categories

Find more on Modeling in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!