Prev: simulink
Next: L parameter in windowing
From: Alex on 20 Mar 2010 09:34 hi, I have a set of 3d coordinates c=[x(1:n);y(1:n);z(1:n)] I need to find the distance between each point. possibly avoiding looping through. since the number of points is generally huge. the ideal result would be to get a matrix (size(c,2) x size(c,2)) with all the combinations. thanks alex
From: John D'Errico on 20 Mar 2010 09:56 "Alex " <demarco_alex(a)yahoo.it> wrote in message <ho2isb$h27$1(a)fred.mathworks.com>... > hi, > I have a set of 3d coordinates c=[x(1:n);y(1:n);z(1:n)] > > I need to find the distance between each point. possibly avoiding looping through. since the number of points is generally huge. > the ideal result would be to get a matrix (size(c,2) x size(c,2)) with all the combinations. > You do realize that if you really do have a HUGE set of points, then nothing you do will allow you to compute this matrix? Suppose that you have 100,000 points. Then your matrix will have 10^10 elements. Each distance requires 8 bytes to store as a double, so you will need only about 80 gigabytes of RAM. Even for 10,000 elements, this will come to 800 megabytes of RAM, a very big matrix. If what you think of as big is smaller than those numbers, you can use my ipdm from the file exchange to compute these interpoint distances efficiently. http://www.mathworks.com/matlabcentral/fileexchange/18937 If you wish to write the distance computation yourself, it is not that difficult using bsxfun to compute a Euclidean distance matrix in a way that is both efficient and numerically accurate. D = sqrt(bsxfun(@minus,C(1,:)',C(1,:)).^2 + ... bsxfun(@minus,C(2,:)',C(2,:)).^2 + ... bsxfun(@minus,C(3,:)',C(3,:)).^2); John
From: Alex on 20 Mar 2010 11:50 "John D'Errico" <woodchips(a)rochester.rr.com> wrote in message <ho2k5i$5jh$1(a)fred.mathworks.com>... > "Alex " <demarco_alex(a)yahoo.it> wrote in message <ho2isb$h27$1(a)fred.mathworks.com>... > > hi, > > I have a set of 3d coordinates c=[x(1:n);y(1:n);z(1:n)] > > > > I need to find the distance between each point. possibly avoiding looping through. since the number of points is generally huge. > > the ideal result would be to get a matrix (size(c,2) x size(c,2)) with all the combinations. > > > > You do realize that if you really do have a HUGE set of > points, then nothing you do will allow you to compute > this matrix? > > Suppose that you have 100,000 points. Then your > matrix will have 10^10 elements. Each distance requires > 8 bytes to store as a double, so you will need only about > 80 gigabytes of RAM. Even for 10,000 elements, this > will come to 800 megabytes of RAM, a very big matrix. > > If what you think of as big is smaller than those numbers, > you can use my ipdm from the file exchange to compute > these interpoint distances efficiently. > > http://www.mathworks.com/matlabcentral/fileexchange/18937 > > If you wish to write the distance computation yourself, > it is not that difficult using bsxfun to compute a > Euclidean distance matrix in a way that is both > efficient and numerically accurate. > > D = sqrt(bsxfun(@minus,C(1,:)',C(1,:)).^2 + ... > bsxfun(@minus,C(2,:)',C(2,:)).^2 + ... > bsxfun(@minus,C(3,:)',C(3,:)).^2); > > John Thank you very much! it works beautifully! I can subdivide my sets to get a pool matrices containing partial results. Alex
|
Pages: 1 Prev: simulink Next: L parameter in windowing |