%% Find Edit Distances to Nearest Words
% Create an edit distance searcher.

vocabulary = ["MATLAB" "Text" "Analytics" "Toolbox"];
eds = editDistanceSearcher(vocabulary,2);

% Find the nearest words and their edit distances to "Test" and "Analysis".

words = ["Test" "Analysis"];
[idx,d] = knnsearch(eds,words)

% Get the words from the vocabulary using the returned indices.

nearestWords = eds.Vocabulary(idx)

% Changing the word "Test" to "Text" requires one edit: a substitution. Changing the word "Analysis" into "Analytics" requires two edits: a substitution and an insertion.
% Copyright 2018 The MathWorks, Inc.