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$>
References: <i0jemg$hka$> <i0jpbo$97t$> <i0k42v$2lg$> <i0klds$dl1$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1278549363 23428 (8 Jul 2010 00:36:03 GMT)
NNTP-Posting-Date: Thu, 8 Jul 2010 00:36:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 952911
Xref: comp.soft-sys.matlab:651250

"Matt Fig" <> wrote in message <i0klds$dl1$>...
> 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.