Repeated values (multiple data points at the same location).

3 ビュー (過去 30 日間)
Kyriakos Kokolakis
Kyriakos Kokolakis 2016 年 2 月 21 日
コメント済み: Star Strider 2016 年 2 月 22 日
Hi all,
I have an array of data and in the first column there are some repeated values (multiple data points at the same location). With those repeated values I'd like to average the associated data in column 2.
Example array: [1 3.1; 2 4.5; 3 5.7; 4 8.2; 4 5.2;]
I'd like to create a new array that looks like this: [1 3.1; 2 4.5; 3 5.7; 4 6.7;]
Thanks for any help.
-K

採用された回答

Star Strider
Star Strider 2016 年 2 月 21 日
The accumarray function will do this if you ask it nicely:
ExArray = [1 3.1; 2 4.5; 3 5.7; 4 8.2; 4 5.2;];
[UExA, ia, ic] = unique(ExArray(:,1));
Out = [ExArray(ia,1) accumarray(ic, ExArray(:,2), [], @mean)]
Out =
1 3.1
2 4.5
3 5.7
4 6.7
  4 件のコメント
Kyriakos Kokolakis
Kyriakos Kokolakis 2016 年 2 月 22 日
Thank you very much!
Star Strider
Star Strider 2016 年 2 月 22 日
My pleasure!
Your problem was fun to solve!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by