Advertisement

MATLAB中实现编辑距离计算及相似度计算

阅读量:

编辑距离,亦称为Levenshtein距离,指的是将一个字符串转换为另一个字符串所需执行的最少编辑操作次数。允许的编辑操作涵盖字符替换、字符插入以及字符删除三种方式。

似乎在R2018a版本中已内置了编辑距离的相关API函数,但当前环境并未安装2018a版本。

dist = edr(x,y,tol)

[dist,ix,iy] = edr(x,y,tol)

[___] = edr(x,y,maxsamp)

[___] = edr(___,metric)

edr(___)

因此无法使用该功能,只能采用手动编写的方式实现。

代码如下:

复制代码
 function [V,m,n] = EditDist(string1,string2)

    
 % Edit Distance is a standard Dynamic Programming problem. Given two strings s1 and s2, the edit distance between s1 and s2 is the minimum number of operations required to convert string s1 to s2. The following operations are typically used:
    
 % Re

全部评论 (0)

还没有任何评论哟~