Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: euclidean distance
Date: Tue, 30 Jun 2009 21:25:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 22
Message-ID: <h2dvrf$imn$1@fred.mathworks.com>
References: <h2dp5l$p98$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1246397103 19159 172.30.248.37 (30 Jun 2009 21:25:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 30 Jun 2009 21:25:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1700436
Xref: news.mathworks.com comp.soft-sys.matlab:551838



First I would advise to preallocate the resulting matrix like

Eucl_Ideal=zeros(size(A,1),size(B,1));

in advance to the for loop.

Regards,
Stefan


"kudrah " <elzarogia@yahoo.gr> wrote in message <h2dp5l$p98$1@fred.mathworks.com>...
> Hi everyone!
> Im trying to calculate the euclidean distance between 2 matrices that contain 3d points.The matrices are quite large,eg A=19500x3 and B=2000x3.I want to calculate the distance between each point of A to each point of B and thus produce a 19500x2000 matrix.So far i wrote this but it takes like forever..Is there any faster way???
> 
> for i=1:size(A,1);
>     for k=1:size(B,1);
> Eucl_Ideal(i,k)=norm(A(i,:)-B(k,:));
>     end 
> end
> 
> Thank you in advance!!!!