How can I make automatic calculation for averages for given ranges?
조회 수: 1 (최근 30일)
이전 댓글 표시
I have 4 case with different x and y values. I want to combine these 4 cases. When doing this combination, if there are some x values in common then I want to take average. Basically, there are 4 case and I want to combine them according to their inputs ( x ). First A, x is between 0.0703-0.1771 Second B, x is between 0.0937-0.2361 Third C, x is between 0.1406-0.3541 Fourth D, x is between 0.2812-0.7083.
I want to calculate y values in average. If there are some x values in use for 2 or 3 case (i.e. 0.1505 is in A, B and C) to take average I want to divide by number of case that include this value. For example, x from 0.0703 to 0.0936, there is only one case, then no need to take average.
Thank you in advance.
댓글 수: 7
Image Analyst
2017년 12월 12일
Not sure I follow. Hopefully you have arrays and not a bunch of separately named variables, like y24 is really y(2,4). Anyway, check out ismembertol() and see if it does what you want.
답변 (1개)
Image Analyst
2017년 12월 10일
Try this:
range1 = x >= 0.0703 & x <= 0.1771
range2 = x >=0.0937 & x <=0.2361
range3 = x >= 0.1406 & x <=0.3541
range4 = x >= 0.2812 & x <=0.7083
sumA = sum(A(range1));
sumB = sum(B(range2));
sumC = sum(C(range3));
sumD = sum(D(range4));
numTerms = sum(range1+range2+range3+range4)
overallMean = (sumA + sumB + sumC + sumD) / numTerms
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!