Averaging over certain elements in an array ?

Hi, I have the following array :
a=[1,1,1;1,2,1;1,3,1;1,7,1;1,8,1;2,4,2;4,5,2;4,6,2;3,3,3;4,5,3;5,6,4;];
rn = unique(a(:,3));
I would like to average all the a(:,1) & a(:,2) such that a(:,3) belongs to elements of rn, and store it another array, say C. For example, in this case, I would like to average C(1,1)=mean(a(1:5,1)), C(1,2)=mean(a(1:5,2)) , C(2,1)=mean(a(6:8,1)), C(2,2)=mean(a(6:8,2)) ... and so on

 採用された回答

Matt J
Matt J 2017 年 12 月 3 日

1 投票

Use accumarray, as illustrated in this recent thread, very similar to yours

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLanguage Fundamentals についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by