Path: news.mathworks.com!not-for-mail
From: "aasim Azooz" <aasimazooz@yahoo.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to vectorize this?
Date: Tue, 27 May 2008 15:52:05 +0000 (UTC)
Organization: Mosul University
Lines: 36
Message-ID: <g1han5$prb$1@fred.mathworks.com>
References: <g1h5v5$o85$1@fred.mathworks.com>
Reply-To: "aasim Azooz" <aasimazooz@yahoo.com>
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 1211903525 26475 172.30.248.35 (27 May 2008 15:52:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 27 May 2008 15:52:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 277505
Xref: news.mathworks.com comp.soft-sys.matlab:470643



"David Doria" <daviddoria@gmail.com> wrote in message 
<g1h5v5$o85$1@fred.mathworks.com>...
> Frequently I would like to operate on a matrix one row at 
a
> time. I always give up and resort to a for loop in a case
> like this.  Can someone explain how you would vectorize 
this
> loop?
> 
> forward = [1 2 3];
> location = [4 5 6];
> 
> %Points is a matrix like this:
> %x1 y1 z1
> %x2 y2 z2
> %x3 y3 z3
> %etc
> 
> for counter = 1:size(Points,1)
>   b = Points(counter, :) - location;
>   projected = dot(forward,b);
>   L(counter,1) = norm(projected);
>   L(counter,2) = Points(counter,2);
> end
> 
> Thanks!
> Dave

if x is an nXm matrix then setting 
y=x(1,:)
will give you the first raw of x in y
y=x(2,:)
will give you the second raw
stop going back to old good memories of fortran and basic
Aasim Azooz