Filter löschen
Filter löschen

operations on large dataset

4 Ansichten (letzte 30 Tage)
gianluca
gianluca am 6 Jan. 2015
Beantwortet: Guillaume am 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

Akzeptierte Antwort

Guillaume
Guillaume am 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]

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by