matrix - How to find x number of closest neighbours matching criteria in MATLAB? -
i have m*n matrix values of 0-9. basically, want able find cells have 0 value , find k closest neighbours aren't 0.
my code right along lines of this:
locate cells 0 , make a*2 matrix holding x , y locations
do same cells without 0
make loop cycles through each given 0 coordinate , measure distance every non-zero cell , record in row 1 of new matrix (row 2 , 3 x , y coordinates, respectively)
use sortrows() matrix in ascending order , extract first k values (ie, closest k number of coordinates)
repeat
what hoping more along lines of finding k closest non-zero cells without internal loop , repeating each 0 cell. advice appreciated, much.
i solve problem finding nonzero entries, e.g. doing, , determining corresponding vertices. can use dsearchn find k nearest points. if want repeatedly, benefit constructing delaunaytriangulation object.
Comments
Post a Comment