help me understand accumarray
이전 댓글 표시
hi i was reading on accumarray (https://www.mathworks.com/help/matlab/ref/accumarray.html) and I do not understand how matrix A was computed (attached picture) - how the second column of subs was manipulated and the zeros in A. Could someone explain how it is computed?
채택된 답변
추가 답변 (1개)
Jordan
2025년 3월 3일
0 개 추천
For the simplest case shown in the first example as well as the image at the end of the function page. The acumarray function takes in two inputs for example vectors, ind and data. These must be equal lengths and thus the ind vector serves to index the data vector. The function then applies an input function, argument number 4 (fun), or by default applies the sum function to the data vector. The function is applied according to the unique indexes present in ind corresponding to values in data. Thus for the first example with inputs "data = [1 2 3 4 5 6]" and "ind = [1 3 4 2 4 1]" acumarray sums the '1' indexes 1+6, '2' indexes 4, '3' indexes 2, and '4' indexes 3+5. The result is thus "ans = [7 4 2 8]".
Very confusing documentation for this function in my opinion especially given the lack of detail in the "More About" section.
카테고리
도움말 센터 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!