Search All of the Math Forum:

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

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

 Messages: [ Previous | Next ]
 EBS Posts: 95 Registered: 2/11/09
Re: I'm dense, but...somebody 'splain accumarray() please?
Posted: Jul 10, 2013 3:22 PM

dpb <none@non.net> wrote in message <krk9mr\$5c5\$1@speranza.aioe.org>...
> On 7/10/2013 1:22 PM, Eric Sampson wrote:
> ...
>

> > I must be being dense too ;) because didn't you already show in your
> > example that you can use the ~ operator to ignore return values, like
> > [~,~,c] = unique(a(:,3)); or am I misunderstanding your question?

>
> But I had to save c in order to pass it to the following invocation of
> arrayfun().
>
> It would be _a_good_thing_ since that's the only reason for c to not to
> have to create it in the workplace or local context an have it hanging
> around but rather to have it be a temporary by nesting the function calls.
>
> If it were u that were needed/wanted as the argument, then it could be done.
>
> Sometimes, if the function result is need more than once then it makes
> sense to make the temporary to avoid repeated evaluations, of course
> (there's where enhancing the optimizer comes in if it can recognize
> common expressions and eliminate the second call or not).
>
> That help, hopefully?
>
> --

Ah yes, I think that now I understand what you were referring to. Oddly enough, I submitted an enhancement request recently that you might like, to allow a person to do something like this:

lcontig=accumarray([~,~,c] = unique(a(:,3)),a(:,4),[],@(x) all(abs(diff(x))==1))

The temp variable can be named whatever you want, the crux of the enhancement request is to allow you to next function calls with multiple return arguments, as long as all but one return arg are ignored using ~.

If you like that idea, please email/call TMW support and let them know, so they add your vote to the enhancment request :)

Cheers

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