sales.rep = [1 2 1 3 4 6 2 3 1 1]; sales.amount = [1 1 3 1 5 2 2 4 1 5]; numReps = max(sales.rep); sales.total = zeros(1,numReps); for i = 1 : numel(sales.rep) sales.total(sales.rep(i)) = sales.total(sales.rep(i)) ... + sales.amount(i); end sales.accum = accumarray(sales.rep', sales.amount)'
By Doug Hull
14:37 UTC | Posted in Level: Basic | Permalink |
You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.
Wrap code fragments inside <pre> tags, like this:
<pre class="code"> a = magic(3); sum(a) </pre>
If you have a "<" character in your code, either follow it with a space or replace it with "<" (including the semicolon).
Doug Hull is a proud MathWorker who is on a mission to help you with MATLAB.
These postings are the author's and don't necessarily represent the opinions of The MathWorks.
Recent Comments