Skip to content

Commit

Permalink
Levenshtein distance (Ze)
Browse files Browse the repository at this point in the history
  • Loading branch information
lmendo committed Dec 28, 2019
1 parent 643e39c commit 9ab81ff
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 2 deletions.
Binary file modified funDef.mat
Binary file not shown.
23 changes: 22 additions & 1 deletion funDef.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1462,7 +1462,28 @@ Ye 1 2 1 2 1 1 1 true true true true if numel(in)==1 && (isnumeric(in{1}) || is
else
error('MATL:runtime', 'MATL run-time error: incorrect inputs')
end
Ze 1 1 1 1 1 1 true true true true out{1} = exp(in{:}); exponential \matlab+exp+
Ze 1 2 1 2 1 1 1 true true true true if numel(in)==1 exponential / Levenshtein distance (i) For $1$ input: \matlab+exp+. (ii) For $2$ inputs: Levenshtein distance between char, logical or numeric inputs. Either input can be a cell array, and then the result is a vector or matrix of distances.

out{1} = exp(in{1});
elseif numel(in)==2
% Adapted from https://blogs.mathworks.com/cleve/2017/08/14/levenshtein-edit-distance-between-strings
if ~iscell(in{1}), in{1} = in(1); end
if ~iscell(in{2}) in{2} = in(2); end
R = NaN(numel(in{1}), numel(in{2}));
for ind1 = 1:numel(in{1}), for ind2 = 1:numel(in{2})
s = in{1}{ind1}(:).'; t = in{2}{ind2}(:).';
m = numel(s); n = numel(t);
D = zeros(m+1,n+1); D(:,1) = 0:m; D(1,:) = 0:n;
for ii = 1:m, for jj = 1:n
c = s(ii) ~= t(jj); D(ii+1,jj+1) = min([D(ii,jj+1)+1, D(ii+1,jj)+1, D(ii,jj)+c]);
end, end
R(ind1, ind2) = D(m+1,n+1);
end, end
out{1} = R;
clear s t m n D ii jj c R ind1 ind2
else
error('MATL:runtime', 'MATL run-time error: incorrect number of inputs')
end
f 1 3 1 1 3 1 2 true true true true [out{:}] = find(in{:}); find \matlab+find+
Xf 1 4 2 1 1 1 1 true true true true if numel(in)>1 find one string within another / non-empty substrings (i) If 2 or more inputs: \matlab+strfind+. Works also when the first input is a numeric array or a cell array of numeric arrays. In this case each numeric array is linearized, and results are row vectors. (ii) If 1 input: output is a cell array of all non-empty substrings. Works also for numeric or cell arrays
if ischar(in{1}) || (iscell(in{1})&&ischar(in{1}{1}))
Expand Down
Binary file modified help.mat
Binary file not shown.
Binary file modified spec/MATL_spec.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion spec/funDefTable/funDefTable.tex
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
\matl{Zd} & 1--2 (2 / 1) & 1--3 (1) & \matlab+gcd+, element-wise with singleton expansion. With $1$ input and $1$ output, computes the greatest common divisor of all elements of the input \\
\matl{e} & 1-- (2 / 1) & 1 & (i) With $1$ input: \matlab+squeeze+. (ii) With more than $1$ input: \matlab+reshape+. If second input is logical, inputs beyond the second are ignored. Contiguous equal values in the second input indicate dimensions that will be collapsed; and a final \matlab+[]+ is implicit. If there are $2$ inputs and the second is non-logical and empty, it is replaced by the rounded-up square root of the number of elements of the first input, repeated; thus a square matrix is returned. If there are $2$ inputs and the second is a non-logical scalar, a final \matlab+[]+ is implicit. If size specification doesn't contain \matlab+[]+ (explicit or implicit), the first input is padded or truncated if needed; padding is done with \matlab+0+, \matlab+false+, \matlab+char(0)+ or \matlab+{[]}+ according to type of first input. If size specification contains \matlab+[]+ (explicit or implicit), the first input is padded if needed \\
\matl{Ye} & 1--2 (1 / 2) & 1 & (i) With one numerical or symbolic input: \matlab+expm+. (ii) With one logical input \matlab+M+: the input is interpreted as the adjacency matrix of a graph, which is made square if needed. The \matlab+logical+ version of the adjacency matrix of the power of the graph is computed with increasing exponent until the result no longer changes. This is the same as \matlab+logical(M*expm(M))+ except that numerical precision issues are avoided. (iii) With a logical input \matlab+M+ and a non-negative integer input \matlab+n+: \matlab+M+ interpreted as the adjacency matrix of a graph, which is made square if needed. The \matlab+logical+ version of the adjacency matrix of the power of the graph is computed with exponent \matlab+n+. \sa \matl{Y\textasciicircum{}} \\
\matl{Ze} & 1 & 1 & \matlab+exp+ \\
\matl{Ze} & 1--2 (1 / 2) & 1 & (i) For $1$ input: \matlab+exp+. (ii) For $2$ inputs: Levenshtein distance between char, logical or numeric inputs. Either input can be a cell array, and then the result is a vector or matrix of distances. \\
\matl{f} & 1--3 (1) & 1--3 (1 / 2) & \matlab+find+ \\
\matl{Xf} & 1--4 (2 / 1) & 1 & (i) If 2 or more inputs: \matlab+strfind+. Works also when the first input is a numeric array or a cell array of numeric arrays. In this case each numeric array is linearized, and results are row vectors. (ii) If 1 input: output is a cell array of all non-empty substrings. Works also for numeric or cell arrays \\
\matl{Yf} & 1 & 1 & \matlab+factor+. For input $1$ it returns an empty array, not $1$ like \matlab+factor+ does. For negative input, \matlab+factor+ is applied to the absolute value of the input (so input $-1$ produces $1$). \sa \matl{YF} \\
Expand Down
Binary file modified spec/functionTable/MATL.xlsx
Binary file not shown.
Binary file modified spec/functionTable/function_table.pdf
Binary file not shown.
Binary file modified spec/functionTable/function_table.pdf.old
Binary file not shown.

0 comments on commit 9ab81ff

Please sign in to comment.