How to take an average?
    조회 수: 13 (최근 30일)
  
       이전 댓글 표시
    
I have this array and according to excel histogram plot the mostly values are located in the range [-0.5,0.5]. I want to sort all values from the array A that lies in this range and take there average. How can I do this?

A= [0.0000    0.4341   -0.0000   -0.5910   -0.0352    2.0350   -0.0000   -0.9597    0.0000   -1.2164   -2.7826   -0.0000    0.3716 -0.0000   -0.0000   -0.0000    1.4557    0.0000   -0.0000    0.5599   -0.0000   -0.2463   -0.7001    0.0000] 
댓글 수: 0
채택된 답변
  Raghvi
    
 2023년 3월 17일
        Hey Haya, 
To find the range in which most values are present, you can use the histcount() function: https://www.mathworks.com/help/matlab/ref/histcounts.html 
[n,e] = histcounts(A); 
This will partitions the A values into bins(ranges), and returns the count in each bin(n), as well as the bin edges(e). 
So the maximum values will be present in the range: 
[maxn,i] = max(n); 
range = [e(i), e(i+1)]; 
In this case it will be (0,1) 
To find the average of only these values: 
x = A >= range(1) & A<= range(2); % or > and < instead of >= and <= 
result = mean(A(x)); 
댓글 수: 0
추가 답변 (1개)
  HimeshNayak
    
 2023년 3월 17일
        Hi Haya,
From what I understand, you want to find the average of the range of the elements present in the array. Follow the following steps:
1. Find the range of the element in the array.
[minA, maxA] = bounds(A);
2. Store the range values in an array.
M = [minA, maxA];
3. Find the average / mean of the values.
avg = mean(M); 
Regards
HimeshNayak
댓글 수: 0
참고 항목
카테고리
				Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


