Averaging values in Column B based on serial date in column A

조회 수: 2 (최근 30일)
Claire
Claire 2020년 7월 8일
댓글: Tommy 2020년 7월 8일
Hello
I have an array that looks like:
col A col B
737585 1
737585 2
737585 3
737586 4
737586 5
737586 6
where column A is the serial date and column B is the respective value. I need a for loop that will average the values in col B that have the same serial date as in column A. Thank you!
ex: serial date: 737585 avg: 1+2+3/3 = 2

채택된 답변

Tommy
Tommy 2020년 7월 8일
Does it need to be a loop? I believe this will work:
groups = findgroups(yourArray(:,1));
avg = splitapply(@mean, yourArray(:,2), groups);
  댓글 수: 2
Claire
Claire 2020년 7월 8일
I guess it didn't have to be a loop, that worked perfectly! Thank you so much!!!
Tommy
Tommy 2020년 7월 8일
Happy to help!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by