필터 지우기
필터 지우기

How to filter and group data in matlab

조회 수: 2 (최근 30일)
Léon
Léon 2012년 11월 28일
Hello,
I try to group data in matlab by doing:
Consider a dataset like the following:
data = dataset;
data.groups_a = [1;1;2;1;2;2;2];
data.groups_b = [7;8;9;7;8;9;9];
data.values = [103;187;261;366;271;287;311];
%%Now let's sum up the values for each group in groups_a
[groups_a,~,ICa] = unique(data.groups_a);
[groups_b,~,ICb] = unique(data.groups_b);
groupped_by_a = accumarray(ICa,data.values,[],@nansum);
So this works excellent is quite fast even for large datasets. But how can I now retrieve the values grouped by groups_a AND groups_b? So my matrix should be:
x = zeros(length(groups_a),length(groups_b));
Example:
x(1,1) should be the sum of all values that are in group_a == 1 and group_b == 7. So the correct entry would be x(1,1) = 103 + 366;
Can somebody may point me to the solution? Thank you very much beforehand!
Regards!

채택된 답변

Walter Roberson
Walter Roberson 2012년 11월 29일
accumarray( [ICa, ICb], data.values, [], @nansum)
  댓글 수: 1
Léon
Léon 2012년 11월 29일
So close ;)
Thank you very much !

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by