필터 지우기
필터 지우기

How to take mean of rows of particular value?

조회 수: 2 (최근 30일)
Keegan Carvalho
Keegan Carvalho 2020년 4월 26일
댓글: darova 2020년 4월 27일
I have an excel file with three columns (Year, Month, Temp). I wanted to find the monthly mean of Temp values from 1997 to 2019 i.e. Jan-97, Feb-97 and so on...
Now, the table (file atteached) has many values for Month 1, Month 2, etc. This is because I have extracted values from different grid points and hence is a little messy. It looks like this:
I used the sortrows function to order the table. However, I do not know how to proceed further. My main aim is to sort the data with respect to Month (Jan-1997, Feb-1997 ... Dec-2019) and then calculate the monthly mean of Temp values from Jan-1997 to Dec-2019. Looking forward to your assistance
  댓글 수: 2
darova
darova 2020년 4월 26일
Everything looks correct. Sortred by rows. What is wrong?
Use mean to calculate mean value
Keegan Carvalho
Keegan Carvalho 2020년 4월 26일
편집: Keegan Carvalho 2020년 4월 26일
If you sort the data, there are many 1997s (Year) 1s (Months):
So how would I group (take mean) all of the TEMP values for the Year 1997 and Month 1 and similarly Month 2 and so on? I am thinking maybe to loop the columns but not sure how to go about it.

댓글을 달려면 로그인하십시오.

채택된 답변

darova
darova 2020년 4월 26일
Sort your data and use for loop
schematic code (not tested)
s = 0; % sum of group data
k = 1; % index of group start
for i = 1:n-1
s = s + a(i);
if a(i) ~= a(i+1)
a1(k:i) = s/(i-k+1); % write mean inside a1
s = 0; % zeros sum
k = i; % new group start
end
end
  댓글 수: 10
Keegan Carvalho
Keegan Carvalho 2020년 4월 27일
Wonderful. Thank you very much darova.
Cheers!
darova
darova 2020년 4월 27일
cheers!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by