help me understand accumarray

17 Ansichten (letzte 30 Tage)
Cside
Cside am 27 Okt. 2019
Bearbeitet: Daniel M am 27 Okt. 2019
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?

Akzeptierte Antwort

Daniel M
Daniel M am 27 Okt. 2019
Bearbeitet: Daniel M am 27 Okt. 2019
OK, so the subs matrix represent the rows and columns of the matrix A. (1, 1) represent the first row and first column. (3, 2) represents the 3rd row and 2nd column. If you don't get this, look at the document on ind2sub on this page.
Now the vals are associated with each row in subs (e.g. the first (1, 1) associated with 101, up to (4, 1) with 106). And the values get accumulated in the groups determined by the rows of subs.
Therefore, the two rows of (1, 1) have the values 101 and 104. This adds to 205, which is why A(1,1) = 205. (2, 2) are 102 and 105. Thus, A(2,2) = 207. (3,2) --> 103, A(3,2) = 103. (4,1) --> 106, A(4,1) = 106.
It's pretty clear if you look at the last image on the accumarray page.

Weitere Antworten (0)

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by