operations on large dataset

조회 수: 1 (최근 30일)
gianluca
gianluca 2015년 1월 6일
답변: Guillaume 2015년 1월 6일
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에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by