Prev: I18n:LocaleDatabaseNotFound
Next: STANAG 4539
From: Gordon on 20 Oct 2009 02:36 I would like to quickly determine the nearest neighbour to an element in a matrix that contains a value>=1. For example if I have the matrix data=[1 1 1 1 0 0; 0 1 1 0 0 0; 1 1 1 1 0 0]; and the reference matrix element (3,6) then the desired output would be element number (3,4) similarly for reference matrix element (2,4) then the desired output would be elements (1,4);(2,3);(3,4) I can implement this by calculating the distance matrix between the input reference matrix element (3,6) and all of the values in the data matrix which have a value of 1, and then seeing which is the closest to the point. But given the nature of the data, being in a matrix, it seems to me that there should be a more efficient way of doing this search. For example, start searching the elements closest to the reference matrix element, moving progressively outwards until the desired output is found. Note that I will be doing this search on very large matrices, so ideally I am looking for fairly efficient code. Thanks for any help in advance
|
Pages: 1 Prev: I18n:LocaleDatabaseNotFound Next: STANAG 4539 |