operations on large dataset

4 次查看(过去 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

采纳的回答

Guillaume
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 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by