Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: vectorization question
Date: Tue, 3 May 2011 03:24:05 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 28
Message-ID: <ipnsgl$2u3$1@fred.mathworks.com>
References: <78b117a1-7b10-4ecf-8790-c78e9878aff2@b19g2000yqg.googlegroups.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-05-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1304393045 3011 172.30.248.37 (3 May 2011 03:24:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 3 May 2011 03:24:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:724902

"dal.luc" <dal.luc@gmail.com> wrote in message <78b117a1-7b10-4ecf-8790-c78e9878aff2@b19g2000yqg.googlegroups.com>...
> Hi,
> 
> Is it possible to vectorize this loop :
> 
> 
> obs=3;
> x=[ones(obs,1) [1:obs]'];
> tx=rand(10000,obs);
> for k=1:size(tx,1)
>     y=tx(k,:)';
>     beta=mr(y,x);
>     beta=beta';
>     B(k,:)=beta;
> end
> 
> where mr is a function defined in a m-file
> 
> function b=mr(y,x)
> b=(x'*x)\x'*y;
> 
> Thanks for help
> 
> Lu
- - - - - - - - -
 B = (tx*x)/(x'*x);

Roger Stafford