How to reduce data to categories

1 回表示 (過去 30 日間)
Jeffrey Hawkes
Jeffrey Hawkes 2017 年 1 月 27 日
コメント済み: Jeffrey Hawkes 2017 年 1 月 27 日
I have a large double matrix similar to below
testz(1,:)=[325, 325, 325, 269, 369, 369];
testz(2,:)=[3, 2, 5, 2, 6, 9];
and I would like to reduce the data so that the sum of row 2 (3+2+5 and 2+6+9) is shown for each row 1 value, ie.
test_output =
325 369
10 17
How can I do that?! Thanks in advance...

採用された回答

the cyclist
the cyclist 2017 年 1 月 27 日
編集済み: the cyclist 2017 年 1 月 27 日
testz(1,:)=[325, 325, 325, 369, 369, 369];
testz(2,:)=[3, 2, 5, 2, 6, 9];
[uniquez1,~,idx] = unique(testz(1,:)');
sumz2 = accumarray(idx,testz(2,:)');
test_output = [uniquez1,sumz2]'
(It looks like maybe you wrote "269" once, where you meant "369".)
  1 件のコメント
Jeffrey Hawkes
Jeffrey Hawkes 2017 年 1 月 27 日
yes, you're right. And thanks!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by