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

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 日

0 投票

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 件)

カテゴリ

ヘルプ センター および File Exchange で Dates and Time についてさらに検索

質問済み:

2020 年 7 月 8 日

コメント済み:

2020 年 7 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by