Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Speeding up calculation of matrix
Replies: 5   Last Post: Mar 27, 2012 11:21 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Michael

Posts: 4
Registered: 3/26/12
Re: Speeding up calculation of matrix
Posted: Mar 27, 2012 9:43 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Roger Stafford" wrote in message <jkql7d$5r1$1@newscl01ah.mathworks.com>...
> "Roger Stafford" wrote in message <jkqh5t$ka3$1@newscl01ah.mathworks.com>...
> > [py,px] = ndgrid(0:fit_y,0:fit_x);
> > M = bsxfun(@power,x,reshape(px,1,[]))+bsxfun(@power,y,reshape(py,1,[]));

> - - - - - - - - - -
> As a third alternative you could try this to minimize the total number of power operations (70 vs 240):
>
> n = size(x,1);
> M = reshape(bsxfun(@plus,bsxfun(@power,y,0:fit_y), ...
> reshape(bsxfun(@power,x,0:fit_x),n,1,[])) ,n,[]);
>
> Roger Stafford


Thanks Roger - I am getting about a 30% reduction in run time using this method (after replacing the first function call to @times instead of @plus). Exactly the kind of solution I was looking for. The solution using ndgrid ran a bit slower - the ndgrid call took a while to compute.

Thanks again,
Michael



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.