From: "Richard " <>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Vectorization question (newbie alert)
Date: Fri, 17 May 2013 22:27:06 +0000 (UTC)
Organization: Simon Fraser University
Lines: 24
Message-ID: <kn6arq$c35$>
References: <kn697c$7tp$> <kn6ab1$aqg$>
Reply-To: "Richard " <>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1368829626 12389 (17 May 2013 22:27:06 GMT)
NNTP-Posting-Date: Fri, 17 May 2013 22:27:06 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 391472
Xref: comp.soft-sys.matlab:795755

"James Tursa" wrote in message <kn6ab1$aqg$>...
> "Richard " <> wrote in message <kn697c$7tp$>...
> > Until yesterday, I've never used MATLAB (however I've done a fair amount of programming in languages like C/C++, java, etc.).  I'm trying to assist someone with optimizing one of their modules that takes many hours to run.  Using the profiler, I found that one loop was 
> > Yea?  Nay?
> > 
> > Am I using the correct multiplication operator in my code?
> Yes, assuming that the first loop above has a f = 0 statement prior to loop entry. The following does the same thing using matrix multiplication. It likely won't be any faster for you but I am just showing you another way:
>    j = 1:20
>    f = nn(i,j) * log(p(j)).'; % The matrix multiply essentially does the sum part
> James Tursa

Thanks much for your response, James.  Much appreciated.

I am amazed at the amount of time saved with vectorization.  Clearly the person that originally coded the module wasn't aware of this.

I'm going to try your matrix multiplication version just for giggles!

Thanks again!