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!