Path: news.mathworks.com!not-for-mail
From: Loren Shure <loren@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: how to do this without for loops?
Date: Fri, 10 Aug 2007 07:35:15 -0400
Organization: The MathWorks
Lines: 26
Message-ID: <MPG.2126177f2d6f8fdb98979e@news.mathworks.com>
References: <1186694781.588924.201810@x35g2000prf.googlegroups.com>
NNTP-Posting-Host: shurel.dhcp.mathworks.com
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-15"
Content-Transfer-Encoding: 7bit
X-Trace: fred.mathworks.com 1186745715 19959 144.212.219.159 (10 Aug 2007 11:35:15 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 10 Aug 2007 11:35:15 +0000 (UTC)
User-Agent: MicroPlanet-Gravity/2.70.2067
Xref: news.mathworks.com comp.soft-sys.matlab:423359


In article <1186694781.588924.201810@x35g2000prf.googlegroups.com>, 
b83503104@yahoo.com says...
> Hi,
> 
> I have two vectors, v1 and v2, with possibly different number of
> elements.
> I want to compute a matrix D without using for loops, that stores the
> difference:
> 
> so that
> D(i,j) = v1(i) - v2(j)
> 
> Can anyone show me how to do this without for loops?
> Thanks!
> bahoo
> 
> 

I make sure one is a column and the other a row inside the call to 
bsxfun.

c1 = bsxfun(@minus,a(:),b(:).')

-- 
Loren
http://blogs.mathworks.com/loren/