title: MATLAB using pdist to deal with Time series Clustering
body: <p>I have a problem on time-series data clustering using MATLAB</p>
  
  <p>I am trying to use the DTW library below to be my distance measure method
  <a href="http://www.mathworks.com/matlabcentral/fileexchange/16350-continuous-dynamic-time-warping" rel="nofollow">http://www.mathworks.com/matlabcentral/fileexchange/16350-continuous-dynamic-time-warping</a></p>
  
  <pre><code>TimeData = csvread('testData10.csv',1,0)
  Y = pdist(TimeData,@dtw_dist)
  Z = linkage(Y,'complete')
  dendrogram(Z) 
  </code></pre>
  
  <p>I make a function to fit the format of 'pdist' distance function</p>
  
  <pre><code>function d2 = dtw_dist(XI,XJ)
      [dist,D,k,w,rw,tw] = dtw2(XI,XJ,0)
      d2 = dist
  end
  </code></pre>
  
  <p>but I get the error message</p>
  
  <pre><code>Error using pdist (line 373)
  Error evaluating distance function 'dtw_dist'.
  
  Caused by:
      Error using  - 
      Matrix dimensions must agree.
  </code></pre>
  
  <p>I will be apericiate if anyone helps me</p>
  
  <p>Thanks!</p>
  
  <p>---2015.1.5 update ---</p>
  
  <p>I change my funciton to call dtw to fit the format
  and it works</p>
  
  <pre><code>function d2 = dtw_dist(XI,XJ)
      result =[];
      [m1,n1] = size(XI);
      [m2,n2] = size(XJ);
      for j=1:m2
          result = horzcat(result,dtw(XI,XJ(j,:)));
      end
      d2=result;    
  end
  </code></pre>