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 ]
 Kelly Kearney Posts: 24 Registered: 4/25/13
Re: I'm dense, but...somebody 'splain accumarray() please?
Posted: Jul 11, 2013 11:03 AM

dpb <none@non.net> wrote in message <krkn62\$b02\$1@speranza.aioe.org>...

> Does it eliminate the intermediary storage or only move it to a level
> below the calling function so it does (at least which is _a_good_thing_
> (tm) ) vanish silently?

Yeah, it justs moves the index step into function, so you don't need to worry about it. Regarding getting certain outputs only, perhaps a wrapper function like:

%---
function varargout = outnum(fun, idx, varargin)
% fun: handle to function
% idx: output #s you want to keep
% varargin: input variables to the function
varargout = cell(1, max(idx));
[varargout{:}] = fun(varargin{:});
varargout = varargout(idx);
%---

(I haven't tested that thoroughly, but I think it should work).

So, for example:

test = round(rand(20,1)*10);
accumarray(outnum(@unique,3,test), test, [10 1], @(x) {x})

Again, it only moves the collection and disposal of extra output variables to a different workspace, rather than eliminating it altogether, but it would allow for easier one-liners.
Though perhaps pretty difficult-to-read ones (of course, I feel the same way about bsxfun, especially when I have to combine 3 or 4 bsxfun operators in a single equation).

> > And regarding the other topic of this thread, I also hate the new
> > documentation. But I've been lamenting changes on that front ever since
> > they eliminated the Index... it's simply gotten worse and worse since
> > then. The crash-Matlab-completely-for-no-apparent-reason feature of the
> > R2013a Help Browser is a particularly nice touch, though. Ugh.

>
> That's disheartening to hear it hasn't yet gone away--I found it in R2012b.

Ah, well, I skipped straight from 2012a to 2013a, so I'm just discovering it. Unfortunately, I have to upgrade for my site license, or I think I would gladly revert to R2008b, the last version that I felt truly offered me an upgrade.

>
> --

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