Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Avoiding loops
Date: Wed, 14 Jan 2009 09:58:02 +0000 (UTC)
Organization: Univ of Newcastle upon Tyne
Lines: 27
Message-ID: <gkkcva$4ka$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1231927082 4746 172.30.248.38 (14 Jan 2009 09:58:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 14 Jan 2009 09:58:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1511480
Xref: news.mathworks.com comp.soft-sys.matlab:511391


Can anyone help me with is: I want to do this code more efficient,
can I vectorize the first loop of the parameter mu?

Thanks, 

Jose.

   nv=1000;
   nx=2000;    
    x=rand(nx,2); % data 2D    
    sigma=cov(x)
    y=zeros(1,nx);
        

    for j=1:nv  % Loop in free parameter mu
    mu= [rand(1,1) rand(1,1)]; 
    
    for i=1:nx  % Loop to calculate the likelihood function (lf)
    ir=round(1+(nx-1)*rand(1,1));
    y(i)=(x(ir,:)-mu)*inv(sigma)*(x(ir,:)-mu)';
    end
    
    lf=0.5*sum(y)+nx*0.5*log((det(sigma)))+nx*0.5*d*log(2.0*pi); % likelihood
    p1(j)=lf;
    end    
    p=exp(-sum(p1(j))/nv)