operations on large dataset
1 回表示 (過去 30 日間)
古いコメントを表示
Hi, I want to apply functions on specific data stored in a table (Matrix). The data are of the form:
A = [100123 1 1 2500; 100123 1 2 2502; 100123 2 1 3000; 100123 2 2 3005; 100123 2 3 3003; 100456 1 1 5000; 100456 1 2 5005; 100456 1 3 5003; 100456 2 1 4300; 100456 2 2 4305]
For example I want to compute the mean of the values (4th column) that have the same values in the first and second column. That is the mean between 2500 and 2502 (key = 100123, serie = 1, data = 1 and 2), the mean between 3000, 3005, 3003 (key = 100123, serie = 2, data = 1, 2, 3) and so on.
Tnx for any suggestion, Gianluca
0 件のコメント
採用された回答
Guillaume
2015 年 1 月 6 日
Use unique with the 'rows' option to extract the keys and their position and accumarray to get the mean according to the keys:
A = [100123 1 1 2500; 100123 1 2 2502; 100123 2 1 3000; 100123 2 2 3005; 100123 2 3 3003; 100456 1 1 5000; 100456 1 2 5005; 100456 1 3 5003; 100456 2 1 4300; 100456 2 2 4305];
[keys, ~, indices] = unique(A(:, [1 2]), 'rows');
keysmean = accumarray(indices, A(:, 4), [], @mean);
[keys keysmean]
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!