Path: news.mathworks.com!not-for-mail
From: "Sean " <sean.dewolski@nospamplease.umit.maine.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Calculate distance between many points and one certain point
Date: Wed, 18 Aug 2010 19:30:28 +0000 (UTC)
Organization: University of Maine
Lines: 18
Message-ID: <i4hcck$h6j$1@fred.mathworks.com>
References: <i4hbuo$fd2$1@fred.mathworks.com>
Reply-To: "Sean " <sean.dewolski@nospamplease.umit.maine.edu>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1282159828 17619 172.30.248.35 (18 Aug 2010 19:30:28 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 18 Aug 2010 19:30:28 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2256903
Xref: news.mathworks.com comp.soft-sys.matlab:663150

"JohnMC " <nirmathink@gmail.com> wrote in message <i4hbuo$fd2$1@fred.mathworks.com>...
> I have a large matrix, I want to calculate the distance of each point of the matrix from one certain point which is also in the matrix. 
> 
> if I used a loop, 
> 
> for i= 1:m
>    for j= 1:n
>   dist(i,j) = sqrt((i-x0)^2 + (j-y0)^2));
> end
> end
> 
> Is there any fast way to do this, because the matrix I am processing is large. 
> 
> Thanks a lot.

%
[xx yy] = meshgrid(1:n,1:m);
my_dist = sqrt((xx-x0)^2 + (yy-y0)^2));