Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: problem with division
Date: Wed, 29 Sep 2010 06:50:20 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 31
Message-ID: <i7unjc$po$1@fred.mathworks.com>
References: <i7tked$pdt$1@fred.mathworks.com> <i7tl6p$fne$1@fred.mathworks.com> <i7tvnt$2du$1@fred.mathworks.com>
Reply-To: <HIDDEN>
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 1285743020 824 172.30.248.35 (29 Sep 2010 06:50:20 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 29 Sep 2010 06:50:20 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:674099

"ravi " <ravi_071@hotmail.com> wrote in message <i7tvnt$2du$1@fred.mathworks.com>...
> .......
> I am faced with another similar problem:
> I am given:
> 
> Coords=
> [ 12    23;
>   76     45;
>   29     87]
> 
> The answers are supposed to be
> 
> F_12 = sqrt((76 - 12)^2 + (45 - 23)^2)
> F_13 = sqrt((29 - 12)^2 + (87 - 23)^2)
> F_21 = sqrt((12 - 76)^2 + (23 - 45)^2)
> F_23 = sqrt((29 - 76)^2 + (87 - 45)^2)
> F_31 = sqrt((12 - 29)^2 + (23 - 87)^2)
> F_32 = sqrt((76 - 29)^2 + (45 - 87)^2)
> 
> I'm trying to use bsxfun but is becoming a bit puzzling.
> Asking for some more help.
- - - - - - - - - -
  You don't need bsxfun for this problem.

 n = size(C,1); % Where C is your "Coords"
 p = (1:n^2).';
 p(1:n+1:n^2) = [];
 [I,J] = ind2sub([n,n],p); % Convert to indices in C
 F = sqrt(sum((C(I,:)-C(J,:)).^2,2)); % Where F is your F_12, F_13, etc.

Roger Stafford