Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: looping/vectorising issue...
Date: Thu, 12 Feb 2009 16:57:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 20
Message-ID: <gn1kct$kd8$1@fred.mathworks.com>
References: <gn0vhg$rn$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1234457821 20904 172.30.248.35 (12 Feb 2009 16:57:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 12 Feb 2009 16:57:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:517903

"Rich " <richardwood@removethishotmail.com> wrote in message <gn0vhg$rn$1@fred.mathworks.com>...
> Anyone have any suggestions on how to vectorise this loop? (by vectorise, i guess i mean converting to matrix multiplication)
> 
> I'm at a loss!
> 
> dimensions are:
> z1(m,n)
> z2(m,k)
> z3(m,n*k)
> 
> for i=1:size(z1,1)
>     z3(i,:)=reshape(z1(i,:)'*z2(i,:),1,[]);
> end
> 
> thanks heaps!

 [I,J] = ndgrid(1:n,1:k);
 z3 = z1(:,I).*z2(:,J);

Roger Stafford