• API Main Page
  • Documentation
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

matlab/mex/dtwpath.c

Go to the documentation of this file.
00001 
00026 #include "mex.h"
00027 #include "mex_utils.h"
00028 
00029 #include <stdlib.h>
00030 #include "array.h"
00031 #include "distances.h"
00032 
00033 
00034 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){ 
00035   char msg[2000];
00036   const char *docstring = " [ path ] = dtwpath( s1, s2 );\n"
00037      " s1 and s2 are matrices or vectors giving the signals to be warped.\n\n"
00038      " [ path ] = dtwpath( s1, s2, metric );\n"
00039      " s1 and s2 are matrices or vectors giving the signals to be warped.\n"
00040      " metric is a string giving the distance metric. \todo implement this!\n\n"
00041      " [ path ] = dtwpath( distmat );\n"
00042      " distmat is the n x n pointwise distance matrix between signal points.\n\n";
00043 
00044   /* check proper input and output */
00045   if(nrhs<1){
00046     sprintf(msg, ">> Need at least 1 input.\n%s\n", docstring);
00047     mexErrMsgTxt(msg);
00048   } else if(!is_mex_matrix(prhs[0])){
00049     sprintf(msg, ">> First Input must be a double-precision matrix.\n%s\n", docstring);
00050     mexErrMsgTxt(msg);
00051   } 
00052 
00053   Array *distmat;
00054   if( nrhs==1 ){ /* distance matric */
00055      distmat = mex_mxarray_to_array( prhs[0] );
00056   } else { /* signals + something */
00057      Array *s1 = mex_mxarray_to_array( prhs[0] );
00058      Array *s2 = mex_mxarray_to_array( prhs[1] ); 
00059      distmat=distmatrix_signaldist( vectordist_euclidean, s1, s2, NULL, NULL );
00060      array_free( s1 );
00061      array_free( s2 );
00062   }
00063 
00064   matrix_dtw_cumulate( distmat, FALSE, NULL );
00065   Array *path = matrix_dtw_backtrack( distmat );
00066 
00067   plhs[0]=mex_int_array_to_mxarray( path );
00068 
00069   /* cleaning up */
00070   array_free( path );
00071   array_free( distmat );
00072 
00073   return;
00074 }
00075         

Generated on Fri Jun 25 2010 14:10:16 for libeegtools by  doxygen 1.7.0