- Findgroups: https://www.mathworks.com/help/matlab/ref/findgroups.html#bux3dup
- Splitapply: https://www.mathworks.com/help/matlab/ref/splitapply.html#bux2_9d
- Sortrows: https://www.mathworks.com/help/matlab/ref/double.sortrows.html#bt8bz9j-5
특정 인덱스에 해당하는 데이터 연산에 대해 질문드립니다.
2 ビュー (過去 30 日間)
古いコメントを表示
아래 그림과 같이 첫 번째 'Lot' 열은 상위 항목이고 두 번째 'Ratio' 열은 하위 항목입니다.
그리고 각 항목에 해당하는 'Net' 숫자가 있는 상황에서 동일 항목끼리의 'Net'을 더한 'Sum'이라는 새로운 행렬을 구하고 싶습니다.
문의드린 내용은 최대한 단순화 시킨 예시이고 실제로는 6000 행 이상의 데이터라 단순히 find 함수로 일일이 구할 수 없는 상황임을 알려드립니다.
완전 초보라 for문을 구해서 써야할지 전혀 감이 안오는데 도움 주실 수 있을까요?
엑셀 파일도 첨부하여 올립니다.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1244427/image.png)
0 件のコメント
回答 (1 件)
Varun
2023 年 3 月 21 日
編集済み: Varun
2023 年 3 月 21 日
Hello!
As per my understanding, you want to group the rows of your table using the variables ‘Lot’ and ‘Ratio’ and then, get the sum of the variable ‘Net’. I think a good solution to this would be using the ‘findgroups’ function to group the variables and then, calling ‘splitapply’ to get the sum. The code looks something like this:
G=findgroups(ex.Lot,ex.Ratio)
netsum=splitapply(@sum,ex.Net,G)
However, the rows would have to be sorted when using this, so you can use ‘sortrows’ for this.
You may refer to the following documentation links for:
Hope this helps!
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!