📄 dtw1.m
字号:
function [minDist, dtwPath, dtwTable] = dtw1(vec1, vec2, beginCorner, endCorner, plotOpt)
% dtw1: Dynamic time warping with local paths of 27, 45, and 63 degrees
% Usage: [minDist, dtwPath, dtwTable] = dtw1(vec1, vec2, beginCorner, endCorner, plotOpt)
% vec1: testing vector
% vec2: reference vector
% beginCorner: 1 for anchored beginning
% endCorner: 1 for anchored ending
% plotOpt: 1 for plotting the DTW path
% minDist: minimun distance of DTW
% dtwPath: optimal path of DTW (Its size is 2xk, where k is the path length.)
% dtwTable: DTW table
%
% For example:
% vec1=[71 73 75 80 80 80 78 76 75 73 71 71 71 73 75 76 76 68 76 76 75 73 71 70 70 69 68 68 72 74 78 79 80 80 78];
% vec2=[69 69 73 75 79 80 79 78 76 73 72 71 70 70 69 69 69 71 73 75 76 76 76 76 76 75 73 71 70 70 71 73 75 80 80 80 78];
% [minDist, dtwPath, dtwTable] = dtw1(vec1, vec2);
% dtwplot(vec1, vec2, dtwPath);
% Roger Jang, 20021225, 20060614
if nargin<1, selfdemo; return; end
if nargin<3, beginCorner=1; end
if nargin<4, endCorner=1; end
if nargin<5, plotOpt=0; end
% If input is vector, make it row vector
if size(vec1,1)==1 | size(vec1,2)==1, vec1 = vec1(:)'; end
if size(vec2,1)==1 | size(vec2,2)==1, vec2 = vec2(:)'; end
if nargout<2
minDist=dtw1mex(vec1, vec2, beginCorner, endCorner);
else
[minDist, dtwPath, dtwTable]=dtw1mex(vec1, vec2, beginCorner, endCorner);
end
% Plotting if necessary
if plotOpt==1, dtwplot(vec1, vec2, dtwPath); end
% ====== Self demo
function selfdemo
vec1=[71 73 75 80 80 80 78 76 75 73 71 71 71 73 75 76 76 68 76 76 75 73 71 70 70 69 68 68 72 74 78 79 80 80 78];
vec2=[69 69 73 75 79 80 79 78 76 73 72 71 70 70 69 69 69 71 73 75 76 76 76 76 76 75 73 71 70 70 71 73 75 80 80 80 78];
[minDist, dtwPath, dtwTable] = dtw1(vec1, vec2);
dtwplot(vec1, vec2, dtwPath);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -