Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.


dpb
Posts:
9,242
Registered:
6/7/07


Re: I'm dense, but...somebody 'splain accumarray() please?
Posted:
Jul 10, 2013 2:09 PM


On 7/9/2013 10:00 AM, Steven_Lord wrote: > "dpb" <none@non.net> wrote in message > news:krf8cj$5kh$1@speranza.aioe.org... >> On 7/8/2013 10:42 AM, Steven_Lord wrote: >> ... ...
> If it helps, think of ACCUMARRAY as sort of a "binning" tool like HIST. > All the values with the same row of indices in subs get shoved into the > same bin and then each bin gets processed into a scalar. > >> BTW, I'm beginning to get mind around accumarray, cellfun, bsxfun and >> friends...
OK, I've managed to write a few answers w/ accumarray and cellfun now; I had actually gotten moderately comfortable w/ bsxfun earlier in the summer while tutoring an intern long distance...
Now, a slight diversion/extension  is there any syntax that will allow for building a cell array whose contents in each cell are (say) a variablelength vector w/ the cell being addressed like accumarray or cellfun?
Specifically there's a question at Answers now where the poster is looking to identify a set of contiguous numbers ordered by a second index variable. His actual request was nebulous to begin with so I started w/ returning a logical of which subset was/wasn't contiguous
>> [u,~,c] = unique(a(:,3)); >> lcontig=accumarray(c,a(:,4),[],@(x) all(abs(diff(x))==1)) lcontig = 1 0 0 >>
That wasn't what the requestor actually wanted; amplified the question to say needed the number of missing values in each subsection. That's also easy enough...just change the function a little
>> nmiss=accumarray(c,a(:,4),[],@(x) length([min(x):max(x)])length(x)) nmiss = 0 1 2 >>
OK, that's background; here's the question  what if the desire is now expanded to know who's missing in the set [min(x):max(x)] above? That can be from the empty set to a set of nmiss and the logical way to return the results would be a cell array of that length for each group.
I can't seem to find any syntax outside the loop that works.
As a secondary to that, is there any syntax by which one can eliminate the need for the temporary to hold the alternate optional return value from the call to unique() above? This would be useful in general, far more than just in accumarray and friends.




