Averaging where Bins are various sizes
    조회 수: 1 (최근 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
참고 항목
카테고리
				Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
