Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.



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.
It's a balancing act. If the table of contents for the "Getting Started" 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 To contact Technical Support use the Contact Us link on 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)



