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 ]
 Steven Lord Posts: 18,038 Registered: 12/7/04
Re: I'm dense, but...somebody 'splain accumarray() please?
Posted: Jul 9, 2013 11:00 AM

"dpb" <none@non.net> wrote in message news:krf8cj\$5kh\$1@speranza.aioe.org...
> On 7/8/2013 10:42 AM, Steven_Lord wrote:
> ...
>

>> Have you used the accumulation behavior of SPARSE in the past?
>
> Nope; I've _rarely_ even used sparse as my problems generally didn't fit
> that space...
>
> Thanks for the notes, Steven; I'll study them at length and maybe the
> lightbulb will come on.

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 but they're all also new toys w/ the release 2012b that didn't
> have access to before. Plus, of course, anonymous functions and all that
> entails... :) And, since day job is farming and this is just playing, the
> amount of time to really devote isn't great...

If you've used inline functions, anonymous functions are at their most basic
similar: a way to write one expression as a function without requiring you
to create a separate function file or subfunction. However I feel anonymous
functions are more flexible and more powerful, in particular when it comes
to composition.

f = @(x) x.^2; % square x
g = @(x) sin(x)+cos(x);
h = @(x) g(f(x)); % sin(x.^2)+cos(x.^2)
h(0:5)

To do that with inline functions would be more complicated and the calling
syntax would be much less simple. [*]

> It does seem to me that the amount of basic explanatory text in relation
> to the specific syntax has dropped significantly w/ the new help
> documentation combined w/ the explosion in functionality. It seems like
> the "Getting Started" documentation could/(should?) probably grow by order
> of magnitude for such features.

documentation looks like the TOC for War and Peace, it would be intimidating
for new users. In addition, ACCUMARRAY is not exactly what I would call an
introductory function. I think few people will jump right in and start using
ACCUMARRAY their first day.

I think the mental model for the documentation staff for "Getting Started"
is what do new users need in order to get them started using MATLAB. As I
look at Getting Started now, all of the topics seem like things that a new
user may need to do in their first week of using MATLAB. The basics of
working with the Desktop? Sure, absolutely. Matrices and Arrays? Can't do
much in MATLAB without them. Indexing? Ditto.

Maybe we need an "Intermediate MATLAB Programming" documentation section
that discusses some of the more advanced topics, like matrix
creation/manipulation with BSXFUN, ACCUMARRAY, etc.? What do others think?

--
Steve Lord
slord@mathworks.com
http://www.mathworks.com

[*]
f2 = inline('x.^2', 'x');
g2 = inline('sin(x)+cos(x)', 'x');
h2 = inline('g(f(x))', 'x', 'f', 'g'); % Note h2 must accept three inputs,
not one like h did
h2(0:5, f2, g2)

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