Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Speeding up calculation of matrix
Date: Mon, 26 Mar 2012 20:57:17 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 11
Message-ID: <jkql7d$5r1$1@newscl01ah.mathworks.com>
References: <jkqeso$bup$1@newscl01ah.mathworks.com> <jkqgse$jaa$1@newscl01ah.mathworks.com> <jkqh5t$ka3$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1332795437 5985 172.30.248.47 (26 Mar 2012 20:57:17 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 26 Mar 2012 20:57:17 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:762265

"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