add matlab codes and doc for nearest neighbor model