operations on large dataset

1 vue (au cours des 30 derniers jours)
gianluca
gianluca le 6 Jan 2015
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

Réponse acceptée

Guillaume
Guillaume le 6 Jan 2015
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]

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by