How to add values in a vector based on repeating values on another?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi
I have two vectors of the same length
and
. I want it to be so that everytime a value in the first array repeats(for example the 2 in 1 and 9) the values in the second array would add up(so 7.8953..+8.5184).
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/532084/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/532089/image.png)
댓글 수: 0
채택된 답변
Walter Roberson
2021년 2월 26일
accumarray(first_vector, second_vector)
This requires that first_vector is positive integers. The size of the result will be max(first_vector) x 1
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!