Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
vectorization question

Subject: vectorization question

From: dal.luc

Date: 2 May, 2011 05:59:11

Message: 1 of 2

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

Luc

Subject: vectorization question

From: Roger Stafford

Date: 3 May, 2011 03:24:05

Message: 2 of 2

"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

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us