The Math Forum

Search All of the Math Forum:

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

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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 ]

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$>...
> "Roger Stafford" wrote in message <jkqh5t$ka3$>...
> > [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,

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

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.