```Path: news.mathworks.com!newsfeed-00.mathworks.com!nlpi057.nbdc.sbc.com!prodigy.net!news.glorb.com!news2.glorb.com!postnews.google.com!z6g2000pre.googlegroups.com!not-for-mail
From: NZTideMan <mulgor@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Vectorize Difference Between Two Sets of Points
Date: Mon, 26 Jan 2009 14:16:51 -0800 (PST)
Lines: 41
NNTP-Posting-Host: 202.78.152.105
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1233008212 16665 127.0.0.1 (26 Jan 2009 22:16:52 GMT)
NNTP-Posting-Date: Mon, 26 Jan 2009 22:16:52 +0000 (UTC)
posting-account=qPexFwkAAABOl8VUndE6Jm-9Z5z_fSpR
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5)
Gecko/2008120122 Firefox/3.0.5,gzip(gfe),gzip(gfe)
X-HTTP-Via: 1.1 nc2 (NetCache NetApp/6.0.5P1)
Xref: news.mathworks.com comp.soft-sys.matlab:514095

On Jan 27, 10:51=A0am, Bill Woessner <woess...@gmail.com> wrote:
> I'm sure this question has been asked and answered dozens of times.
> But for the life of me, I can't find the answer.
>
> I have two sets of 2D points, call them A and B. =A0They're stored in
> matrices such that size(A) =3D [M 2] and size(B) =3D [N 2]. =A0For each a=
in
> A and b in B, I need to compute a - b. =A0This is painfully slow using
> for loops. =A0I've been trying to use repmat to speed it up, but so
> far... it's hideous:
>
> M =3D length(A);
> N =3D length(B);
>
> A2 =3D zeros(M, 1, 2);
> A2(:, 1, :) =3D A;
> A2 =3D repmat(A2, [1 N 1]);
>
> B2 =3D zeros(1, N, 2);
> B2(1, :, :) =3D B;
> B2 =3D repmat(B2, [M 1 1]);
>
> delta =3D A2 - B2;
>
> A and B are relatively small so memory is not a concern. =A0But speed
> is. =A0I know there's probably a better way to accomplish this. =A0Can
> someone please point me in the right direction?
>