フィルターのクリア

Repeating Values List Problemc

2 ビュー (過去 30 日間)
Maxwell Barton
Maxwell Barton 2019 年 12 月 20 日
コメント済み: Maxwell Barton 2019 年 12 月 20 日
I have two lists ix and iy, an example of which is shown below. I want to match any repeating values of ix with the corresponding points of iy and then average the points in iy. For example, [4 5 6] in iy all match with 12 in ix, so I would want to average [4,5,6] = 5, and replace all the duplicate 12s in ix with just a single 12, and replace [4 5 6] with 5. Is there a simple way to do this in MATLAB?
ix = [10 11 12 12 12]; iy = [2 3 4 5 6];
ixnew = [10 11 12]; iynew = [2 3 5];

採用された回答

Stephen23
Stephen23 2019 年 12 月 20 日
編集済み: Stephen23 2019 年 12 月 20 日
>> ix = [10,11,12,12,12];
>> iy = [2,3,4,5,6];
>> [ixnew,~,idx] = unique(ix(:),'stable');
>> iynew = accumarray(idx(:),iy(:),[],@mean)
iynew =
2
3
5
>> ixnew
ixnew =
10
11
12
  1 件のコメント
Maxwell Barton
Maxwell Barton 2019 年 12 月 20 日
Thanks a lot mate!

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by