How to neatly sum values of histogram bins, given a value matrix and an associated category association matrix (bin association)
<p>Consider the example following below, where I have a <code>10x10</code> matrix, say <code>A</code>, of random values in some range, say <code>[-5, 5]</code>. I quantize the values of <code>A</code> into 8 categories, <code>1, ..., 8</code>, such that an additional <code>10x10</code> matrix, say <code>qA</code>, describes the category association for each number in <code>A</code>. Finally, I produce the sums of all values assigned to each category. My question regards this final step.</p>

<pre><code>myRange = 5; % values in open interval [-myRange, myRange]
A = myRange*(2*rand(10) - 1);
qA = uencode(A, 3, myRange)+1;

% (+) create "histogram" of sum of values assigned to each bin
myHistogram = zeros(8,1);
for i = 1:numel(A)
    myHistogram(qA(i)) = myHistogram(qA(i)) + A(i);
end

bar(myHistogram)
</code></pre>

<p><strong>Question:</strong> Is the some neater way of doing this, specifically the counting step <code>(+)</code> above? (Some better alternative than explicitly iterating over each element in the matrix <code>A</code>?).</p>