Hi matlab community
Suppose i have matrix:
a = [1,3,3,2,2,3,3,4,3,1,3];
b = [1,1,1,3,4,1,2,1,4,1,1];
c = [2,2,2,4,2,3,3,2,1,3,8];
now, I want to get the mean value (from matrix c) of the intersection of matrices [ab] which have the same value, like this:
a = [1,3,2,2,3,4,3];
b = [1,1,3,4,2,1,4];
c = [2.5,3.75,4,2,3,2,1]; %final result
how to do it? tks :)

 採用された回答

Ive J
Ive J 2021 年 10 月 16 日

0 投票

This should work:
a = [1,3,3,2,2,3,3,4,3,1,3];
b = [1,1,1,3,4,1,2,1,4,1,1];
c = [2,2,2,4,2,3,3,2,1,3,8];
x = [a; b];
[~, ia, ic] = unique(x.', 'stable', 'rows');
newC = arrayfun(@(x) mean(c(ic == x)), unique(ic)).'
newC = 1×7
2.5000 3.7500 4.0000 2.0000 3.0000 2.0000 1.0000

1 件のコメント

eko supriyadi
eko supriyadi 2021 年 10 月 16 日
interesting answer, next is:
d=[a(ia)' b(ia)' newC].';
then if there is another method can be replied here.. tks Ive

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2021 年 10 月 16 日

コメント済み:

2021 年 10 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by