Search All of the Math Forum:

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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

 Messages: [ Previous | Next ]
 dpb Posts: 9,850 Registered: 6/7/07
Re: I'm dense, but...somebody 'splain accumarray() please?
Posted: Jul 10, 2013 3:19 PM

On 7/10/2013 1:35 PM, Kelly Kearney wrote:
...

> I forget how the hell I learned this trick, because the documentation
> for the SZ input to accumarray is confusing at best (rereading it now,
> it still doesn't make any sense to me, even knowing what the effect is).
> Anyway, to get cell array output from your example, add that third
> input, and make sure your function returns a cell array:
>

>>> a = [1 1 1 2 2 2 2 3 3 3];
>>> b = [1 2 3 4 5 8 10 5 6 8];
>>> [u,~,c] = unique(a);

>
>>> groups = accumarray(c,b, [length(u) 1], @(x) {x})
>>> missing = accumarray(c,b, [length(u) 1], @(x) {setdiff(min(x):max(x),
>>> x)})

Brilliant!!! :)

I agree on the doc re: SZ argument; I puzzled over it at length
initially and gave up. I've not yet pursued all of Steven's in depth
enough to know if that helps on that point or not but thanks...this
really solves several things have seen recently.

--

Date Subject Author
7/5/13 dpb
7/5/13 dpb
7/6/13 james bejon
7/8/13 Steven Lord
7/8/13 dpb
7/9/13 Steven Lord
7/9/13 dpb
7/10/13 Marc
7/10/13 Kim Andrews
7/10/13 dpb
7/10/13 dpb
7/10/13 dpb
7/10/13 EBS
7/10/13 dpb
7/10/13 EBS
7/10/13 dpb
7/10/13 Kelly Kearney
7/10/13 dpb
7/10/13 dpb
7/11/13 Kelly Kearney
7/11/13 dpb
7/10/13 Kelly Kearney
7/10/13 dpb
7/11/13 Steven Lord