function output = nearest(input, data, target)

% compute the distances (well, the squared distances)
dis = repmat(sum(data.*data,2)',size(input,1),1) - ...
      2*input*data' + repmat(sum(input.*input,2),1,size(data,1));
% find the minimum for each input
[val, ind] = min(dis,[],2);
% pull out the corresponding targets and return them
output = target(ind,:);
