mex_normalize.cpp 791 Bytes
Newer Older
MAIRAL Julien's avatar
MAIRAL Julien committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#include <mexutils.h>
#include <common.h>

template <typename T>
inline void callFunction(mxArray* plhs[], const mxArray*prhs[],const int nrhs, const int nlhs) {
   Matrix<T> X;
   getMatrix<T>(prhs[0],X);
   if (nlhs == 1) {
      Vector<T> nrms;
      plhs[0]=createMatrix<T>(1,X.n());
      getVector<T>(plhs[0],nrms);
      normalize(X,nrms);
   } else {
      normalize(X);
   }
}

void mexFunction(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[]) {
   if (nrhs != 1)
      mexErrMsgTxt("Bad number of inputs arguments");

   if (nlhs != 1 && nlhs != 0)
      mexErrMsgTxt("Bad number of output arguments");

   if (mxGetClassID(prhs[0]) == mxDOUBLE_CLASS) {
      callFunction<double>(plhs,prhs,nrhs,nlhs);
   } else {
      callFunction<float>(plhs,prhs,nrhs,nlhs);
   }
}