function [dist, D] = editdistance( str1, str2 )
% function [dist, D] = editdistance( str1, str2 )
%
% Computes the edit distance between str1 into str2
%
% dist - Final distance value
% D    - Complete distance matrix

len1 = length(str1);
len2 = length(str2);

D = zeros(len1,len2);

for i=2:len1+1
	D(i,1) = i-1;
end;
for j=2:len2+1
	D(1,j) = j-1;
end;
for i=2:len1+1
	for j=2:len2+1
		cost = double(str1(i-1) ~= str2(j-1));
		D(i,j) = min( [ D(i-1,j) + 1, D(i,j-1) + 1, D(i-1,j-1) + cost ] );
	end;
end;

dist = D(len1+1,len2+1);

				
				