calculate sum and average of rows that share a common identifier
조회 수: 3 (최근 30일)
이전 댓글 표시
I have an m by n matrix S and an m x 1 vector N with identifiers, one number (integer) in N for each row in S.
I want to calculate the average for those rows in S that have the same identifier in N.
Example: S=[1 2; 3 4; 5 6; 7 8; 9 10];
N=[1 6 6 53 53]';
Desired result: A=[1 2 ; 4 5 ; 8 9]
A(1,:)=average of row 1 in S
A(2,:)=average of rows 2 and 3 in S (they have a common identifier "6")
A(3,:)=average of rows 4 and 5 in S (they have a common identifier "53")
I can of course run a for loop, but it is quite a bit of data, so I thought it might be possible to use matlab's clever matrix notation.
Any suggestions?
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!