Find the nearest words to "MALTAB" and "MatWorks" with edit distance less than or equal to 1.
words = ["MALTAB""MatWorks""analytcs"];
maxDist = 1;
idx = rangesearch(eds,words,maxDist)
idx=3×1 cell array
{1x0 double}
{[ 1]}
{[ 5]}
For "MALTAB", there are no words in the searcher within the specified range. For "MatWorks" and "analytics", there is one result. View the corresponding word for "MatWorks" using the returned index.
nearestWords = eds.Vocabulary(idx{2})
nearestWords =
"MathWorks"
Find the nearest words to "MALTAB", "MatWorks", and "analytcs" with edit distance less than or equal to 3 and their corresponding edit distances.
words = ["MALTAB""MatWorks""analytcs"];
maxDist = 3;
[idx,d] = rangesearch(eds,words,maxDist)
idx=3×1 cell array
{[ 2]}
{[ 1]}
{1x2 double}
d=3×1 cell array
{[ 2]}
{[ 1]}
{1x2 double}
For both "MALTAB" and "MatWorks", there is one word in the searcher within the specified range. For "analytcs", there are two results. View the corresponding words for "analytcs" using the returned indices and their edit distances.
Edit distance searcher, specified as an editDistanceSearcher object.
words — Input words string vector | character vector | cell array of character vectors
Input words, specified as a string vector, character vector, or cell array of character
vectors. If you specify words as a character vector, then the
function treats the argument as a single word.
Data Types: string | char | cell
maxDist — Maximum search distance non-negative number
Maximum search distance, specified as a non-negative number.
The function finds the indices of the words in eds whose edit
distance to the elements of words are fewer than or equal to
maxDist, sorted in the ascending order edit distance.
idx — Indices of nearest neighbors in searcher cell array of vectors
Indices of nearest neighbors in the searcher, returned as a cell array of
vectors.
idx{i} is a vector of indices of the words in
eds whose edit distance to words(i) is less
than or equal to maxDist, sorted in the ascending order edit
distance.
Data Types: cell
d — Edit distances to neighbors cell array of vectors
Edit distances to neighbors, returned as a cell array of vectors.
d{i} is a vector of edit distances between
words(i) and the corresponding words in eds
given by the vocabulary indices idx{i}.