Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: I'm dense, but...somebody 'splain accumarray() please?
Replies: 23   Last Post: Jul 11, 2013 1:00 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
dpb

Posts: 8,296
Registered: 6/7/07
Re: I'm dense, but...somebody 'splain accumarray() please?
Posted: Jul 10, 2013 2:09 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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
variable-length 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.

--



Date Subject Author
7/5/13
Read I'm dense, but...somebody 'splain accumarray() please?
dpb
7/5/13
Read Re: I'm dense, but...somebody 'splain accumarray() please?
dpb
7/6/13
Read Re: I'm dense, but...somebody 'splain accumarray() please?
james bejon
7/8/13
Read Re: I'm dense, but...somebody 'splain accumarray() please?
Steven Lord
7/8/13
Read Re: I'm dense, but...somebody 'splain accumarray() please?
dpb
7/9/13
Read Re: I'm dense, but...somebody 'splain accumarray() please?
Steven Lord
7/9/13
Read Re: I'm dense, but...somebody 'splain accumarray() please?
dpb
7/10/13
Read Re: I'm dense, but...somebody 'splain accumarray() please?
Marc
7/10/13
Read Re: I'm dense, but...somebody 'splain accumarray() please?
Kim Andrews
7/10/13
Read Re: I'm dense, but...somebody 'splain accumarray() please?
dpb
7/10/13
Read Re: I'm dense, but...somebody 'splain accumarray() please?
dpb
7/10/13
Read Re: I'm dense, but...somebody 'splain accumarray() please?
dpb
7/10/13
Read Re: I'm dense, but...somebody 'splain accumarray() please?
EBS
7/10/13
Read Re: I'm dense, but...somebody 'splain accumarray() please?
dpb
7/10/13
Read Re: I'm dense, but...somebody 'splain accumarray() please?
EBS
7/10/13
Read Re: I'm dense, but...somebody 'splain accumarray() please?
dpb
7/10/13
Read Re: I'm dense, but...somebody 'splain accumarray() please?
Kelly Kearney
7/10/13
Read Re: I'm dense, but...somebody 'splain accumarray() please?
dpb
7/10/13
Read Re: I'm dense, but...somebody 'splain accumarray() please?
dpb
7/11/13
Read Re: I'm dense, but...somebody 'splain accumarray() please?
Kelly Kearney
7/11/13
Read Re: I'm dense, but...somebody 'splain accumarray() please?
dpb
7/10/13
Read Re: I'm dense, but...somebody 'splain accumarray() please?
Kelly Kearney
7/10/13
Read Re: I'm dense, but...somebody 'splain accumarray() please?
dpb
7/11/13
Read Re: I'm dense, but...somebody 'splain accumarray() please?
Steven Lord

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.