From: ImageAnalyst <>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Point with the closest distance
Date: Mon, 2 May 2011 14:13:37 -0700 (PDT)
Lines: 20
Message-ID: <>
References: <iplj54$c3t$> <ipmgel$482$>
 <> <ipn0s6$gdn$>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: 1304370817 4319 (2 May 2011 21:13:37 GMT)
NNTP-Posting-Date: Mon, 2 May 2011 21:13:37 +0000 (UTC)
Injection-Info:; posting-host=; posting-account=0rLUzAkAAABojYSRC64DkTbtiSCX77HH
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1,gzip(gfe)
Xref: comp.soft-sys.matlab:724857

On May 2, 3:32 pm, "Deepak " <> wrote:
> Now i need to find the closest point from the axis to the point cloud.
I'm not sure why you didn't try my sorting suggestion.  Any reason?
Just add this to the end of your code:

% Plot it
scatter3(X(:,1), X(:,2), X(:,3));

% Calculate radius squared.
radiiSquared = X(:,1).^2 + X(:,2) .^2
% Sort from smallest radius to largest radius.
[sortedRadii, sortIndexes] = sort(radiiSquared)
% Create the output array.
output = X(sortIndexes, :)

It's a simple matter to subtract off the value of the origin (your
least squares center line) to get the radii squared in case you want
to do that.