Help me, please. I want a matrix transform averaged and unique in specific col,

1 回表示 (過去 30 日間)
Sangjae
Sangjae 2011 年 10 月 20 日
I want first 1 and 2 columns unique and 3 coloum make average matrix.
for example
[1,2,11; 1,2,12; 1,2,13; 2,4,10; 2,4,12]
->
[1,2,12; 2,4,10]
How can I get that? I can do that very complex way but I think there is some smart way. Help me people
  2 件のコメント
Walter Roberson
Walter Roberson 2011 年 10 月 20 日
If you want averaging, then why isn't the second row [2, 4, 11] ?
Sangjae
Sangjae 2011 年 10 月 20 日
yes you're right!! it must be [2,4,11].
sorry for my mistake

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

採用された回答

Andrei Bobrov
Andrei Bobrov 2011 年 10 月 20 日
A = [1,2,11; 1,2,12; 1,2,13; 2,4,10; 2,4,12];
[a,b,c] = unique(A(:,1:2),'rows');
out = [a cellfun(@mean,mat2cell(A(:,end),histc(c,1:max(c)),1))];

その他の回答 (1 件)

Pramod Bhat
Pramod Bhat 2011 年 10 月 20 日
may u please elaborate your question? im not getting ur problem...

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by