groupcounts and sum of data in another array in the same order

조회 수: 5 (최근 30일)
yehuda kristo
yehuda kristo 2023년 12월 13일
편집: Dyuman Joshi 2023년 12월 13일
I have a random signal sample and I have done cycle counting to extract the data that most influence calculation. The result of this cycle counting are 2 arrays, array A which consist of its range (2 x amplitude) and array B which consist of its occurrence (half cycle or full cycle). I want to do groupcounts that count the occurrence of ranges from array A and count the sum of its cycle from the result of the groupcounts.
Example:
A = [10, 11, 12, 10, 11, 12, 13, 11, 15, 10], B = [0.5, 1, 1, 0.5, 0.5, 0.5, 1, 1, 1, 0.5]
The goupcounts on array A will tell me how much do 10, 11, 12, 13, and 15 occured in array A. I want to count the sum of the cycle of each of this ranges (10, 11, 12, 13, and 15). How do I do that?
  댓글 수: 1
Dyuman Joshi
Dyuman Joshi 2023년 12월 13일
편집: Dyuman Joshi 2023년 12월 13일
Do you mean like this?
A = [10, 11, 12, 10, 11, 12, 13, 11, 15, 10];
B = [0.5, 1, 1, 0.5, 0.5, 0.5, 1, 1, 1, 0.5]
B = 1×10
0.5000 1.0000 1.0000 0.5000 0.5000 0.5000 1.0000 1.0000 1.0000 0.5000
[I, K] = findgroups(A)
I = 1×10
1 2 3 1 2 3 4 2 5 1
K = 1×5
10 11 12 13 15
S1 = accumarray(I.', A.')
S1 = 5×1
30 33 24 13 15
S2 = accumarray(I.', B.')
S2 = 5×1
1.5000 2.5000 1.5000 1.0000 1.0000
Edit - Well, it seems I'm late to the party haha.

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

채택된 답변

Voss
Voss 2023년 12월 13일
A = [10, 11, 12, 10, 11, 12, 13, 11, 15, 10], B = [0.5, 1, 1, 0.5, 0.5, 0.5, 1, 1, 1, 0.5]
A = 1×10
10 11 12 10 11 12 13 11 15 10
B = 1×10
0.5000 1.0000 1.0000 0.5000 0.5000 0.5000 1.0000 1.0000 1.0000 0.5000
[counts,vals] = groupcounts(A(:))
counts = 5×1
3 3 2 1 1
vals = 5×1
10 11 12 13 15
sums = groupsummary(B(:),A(:),'sum')
sums = 5×1
1.5000 2.5000 1.5000 1.0000 1.0000

추가 답변 (2개)

Matt J
Matt J 2023년 12월 13일
splitapply(@sum,B,findgroups(A))

Matt J
Matt J 2023년 12월 13일
accumarray(findgroups(A(:)), B(:))

카테고리

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