matlab中的且,新人求问!MATLAB中如何实现编辑距离并求相似度,且遍历输出成矩...

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

从网上找到的编辑距离计算相似度的算法:

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:

% Replacing one character of string by another character.

% Deleting a character from string

% Adding a character to string

% Example:

% s1='article'

% s2='ardipo'

% EditDistance(s1,s2)

% > 4

% you need to do 4 actions to convert s1 to s2

% replace(t,d) , replace(c,p) , replace(l,o) , delete(e)

% using the other output, you can see the matrix solution to this problem

%

%

% by : Reza Ahmadzadeh (seyedreza_ahmadzadeh@yahoo.com - reza.ahmadzadeh@iit.it)

% 14-11-2012

m=length(string1);

n=length(string2);

v=zeros(m+1,n+1);

for i=1:1:m

v(i+1,1)=i;

end

for j=1:1:n

v(1,j+1)=j;

end

for i=1:m

for j=1:n

if (string1(i) == string2(j))

v(i+1,j+1)=v(i,j);

else

v(i+1,j+1)=1+min(min(v(i+1,j),v(i,j+1)),v(i,j));

end

end

end

V=v(m+1,n+1);

end

然后根据最小编辑距离,求两个字符串的相似度

[mindist m n]=EditDist(final_code,final_code2);

1-mindist/max(m,n )

这个算法如何修改可以实现字符串组的遍历并且输出成矩阵呢?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值