Mean value of data with irregular intervals
Show older comments
Hello,
I am trying to obtain average y value for a data set (x,y). However, interval between data points is not regular and mean(y) is off from the expected value. For example,
x = [1 1.1 1.2 1.3 2 3 4 5.1 5.2 5.3 5.4]; y = [0 0.1 0.2 0.3 1 2 1 0.3 0.2 0.1 0];
Because x,y are more densely lying in x = [0 1] and [5 6] intervals, y values in those intervals are weighted more if I take mean(y). Do you know how to avoid this and obtain y value in uniform intervals?
Thanks, Bobo
Accepted Answer
More Answers (1)
One way to weight uniformly...
dx=min(diff(x)); % shortest difference in vector
xi=x(1):dx:x(end); % fill in all values equally
yhat=interp1(x',y',x1'); % and get corresponding y's...
mean(yhat); % obviously can combine steps ...
2 Comments
bobo
on 30 Jul 2013
Andrew Sandeman
on 15 Jun 2023
In my opinion this is the correct answer, not the currently accepted answer.
- This method does not neglect y(1)
- Samples which are obtained more sparsely are weighted more accurately using this interpolation method
Categories
Find more on Descriptive Statistics and Insights 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!