二维dtw算法matlab实现,下载的用MATLAB实现的DTW算法,不会用,跪求大神帮忙
該樓層疑似違規(guī)已被系統(tǒng)折疊?隱藏此樓查看此樓
這是下載的用MATLAB實(shí)現(xiàn)的DTW算法,問(wèn)題是怎么用這個(gè)算法簡(jiǎn)單測(cè)試一下,例如兩個(gè)序列(3,5,6,7,7,1)(3,6,6,7,8,1,1)用這個(gè)算法計(jì)算這兩個(gè)序列的相似性?哪個(gè)大神幫幫忙,本人菜鳥(niǎo)一枚
function [Dist,D,k,w,rw,tw]=dtw(r,t)
%
% [Dist,D,k,w,rw,tw]=dtw(r,t,pflag)
%
% Dynamic Time Warping Algorithm 動(dòng)態(tài)時(shí)間規(guī)整算法
% Dist is unnormalized distance between t and r Dist是t和r之間的非標(biāo)準(zhǔn)化距離
% D is the accumulated distance matrix D是累積的距離矩陣
% k is the normalizing factor k是正態(tài)因子
% w is the optimal path w是最佳路徑
% t is the vector you are testing against t是你要測(cè)試的矢量
% r is the vector you are testing r是你正在測(cè)試的矢量
% rw is the warped r vector rw是扭曲的r矢量
% tw is the warped t vector tw是扭曲的t矢量
% pflag plot flag: 1 (yes), 0(no) pflag圖標(biāo)記:1(yes),0(no)
%
% Version comments: 文本的評(píng)論:
% rw, tw and pflag added by Pau Mic
[row,M]=size(r); if (row > M) M=row; r=r'; end;
[row,N]=size(t); if (row > N) N=row; t=t'; end;
d=sqrt((repmat(r',1,N)-repmat(t,M,1)).^2); %this makes clear the above instruction Thanks Pau Mic
D=zeros(size(d));
D(1,1)=d(1,1);
for m=2:M
D(m,1)=d(m,1)+D(m-1,1);
end
for n=2:N
D(1,n)=d(1,n)+D(1,n-1);
end
for m=2:M
for n=2:N
D(m,n)=d(m,n)+min(D(m-1,n),min(D(m-1,n-1),D(m,n-1))); % this double MIn construction improves in 10-fold the Speed-up. Thanks Sven Mensing
end
end
Dist=D(M,N);
n=N;
m=M;
k=1;
w=[M N];
while ((n+m)~=2)
if (n-1)==0
m=m-1;
elseif (m-1)==0
n=n-1;
else
[values,number]=min([D(m-1,n),D(m,n-1),D(m-1,n-1)]);
switch number
case 1
m=m-1;
case 2
n=n-1;
case 3
m=m-1;
n=n-1;
end
end
k=k+1;
w=[m n; w]; % this replace the above sentence. Thanks Pau Mic
end
% warped waves
rw=r(w(:,1));
tw=t(w(:,2));
end
總結(jié)
以上是生活随笔為你收集整理的二维dtw算法matlab实现,下载的用MATLAB实现的DTW算法,不会用,跪求大神帮忙的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 正交试验设计例题及答案_SPSS正交试验
- 下一篇: matlab retinex,基于Ret