Averaging where Bins are various sizes
2 次查看(过去 30 天)
显示 更早的评论
I have a set of data that I want matlab to do some simple averaging for me Below is an example data set
Time VarA VarB VarC
0 5 103 0
1.011 18 103 0.26
2.031 55 103 0.59
3.051 85 103 0.74
4.081 117 103 1.03
5.101 142 103 1.29
6.121 156 103 1.56
7.151 175 103 1.73
8.171 186 103 1.99
9.192 193 103 2.21
10.222 200 103 2.53
11.242 204 103 2.76
12.262 203 103 3.01
13.282 202 103 3.26
14.292 202 103 3.54
15.322 203 103 3.8
16.342 202 103 4.05
17.363 201 103 4.31
18.383 205 103 4.53
19.413 203 103 4.72
20.438 185 103 5
What I want to do is do some averaging based on inputs. With the above example, I would give it the these intervals [0:0.5:5] to create a the framework of how often I want the averaging. From here what I would want it to do is average based on binning Column 4 (VarC) into sections based on the values. In this case I want all values in columns 2 and 3 averaged for the values between 0 and 0.5, 0.5 and 1.0, 1.0 and 1.5 and so on (until 5.0) and then have them output in a nice matrix for each bin. May be a simple for-loop?
回答(1 个)
Guillaume
2018-1-29
yourtable.Bin = discretize(yourtable.VarC, 0:0.5:5);
meantable = varfun(@mean, yourtable, 'GroupingVariable', 'Bin')
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!