Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to avoid nested for loops
Date: Thu, 8 Jul 2010 00:36:03 +0000 (UTC)
Organization: Carnegie Mellon University
Lines: 11
Message-ID: <i136hj$ms4$1@fred.mathworks.com>
References: <i0jemg$hka$1@fred.mathworks.com> <i0jpbo$97t$1@fred.mathworks.com> <i0k42v$2lg$1@fred.mathworks.com> <i0klds$dl1$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1278549363 23428 172.30.248.35 (8 Jul 2010 00:36:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 8 Jul 2010 00:36:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 952911
Xref: news.mathworks.com comp.soft-sys.matlab:651250

"Matt Fig" <spamanon@yahoo.com> wrote in message <i0klds$dl1$1@fred.mathworks.com>...
> Try this:
> 
> p3 =  bsxfun(@times,2*p1hf,reshape(p1hf,1,1,nb,nb)) -...
>          bsxfun(@times,reshape(p1hf,nb,1,nb),reshape(p1hf,1,nb,1,nb));

Dear Matt,

It seems that bsxfun is the fastest among the suggested routines taking care of the problem in hand. It is slightly faster than for loops, while keeping the code elegant and compact.

Thanks you all for your help.