// btkSetAnalogDescription(h, i, newLabel)
// btkSetAnalogDescription(h, label, newLabel)
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
  if(nrhs < 3)
    mexErrMsgTxt("Three inputs required.");
  if (nlhs > 2)
    mexErrMsgTxt("Too many output arguments.");

  if (!mxIsChar(prhs[2]) || mxIsEmpty(prhs[2]))
    mexErrMsgTxt("Analog's description must be a non-empty string.");    

  btk::Acquisition::Pointer acq = btk_MOH_get_object<btk::Acquisition>(prhs[0]);
  btk::Analog::Pointer analog = btkMXGetAnalog(acq, nrhs, prhs);

  size_t strlen_ = (mxGetM(prhs[2]) * mxGetN(prhs[2]) * sizeof(mxChar)) + 1;
  char* newDesc = (char*)mxMalloc(strlen_);
  mxGetString(prhs[2], newDesc, strlen_);
  analog->SetDescription(newDesc);
  mxFree(newDesc);

  // Return updated analog channels
  btkMXCreateAnalogsStructure(acq, nlhs, plhs);
};
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
  if (nrhs != 3)
    mexErrMsgTxt("Three inputs required.");
  if (nlhs > 2)
    mexErrMsgTxt("Too many output arguments.");

  if ((mxGetClassID(prhs[2]) != mxDOUBLE_CLASS) || mxIsEmpty(prhs[2]) || mxIsComplex(prhs[2]))
    mexErrMsgTxt("The third input must be a vector of real (double) values corresponding to the data of one analog channel."); 

  btk::Acquisition::Pointer acq = btk_MOH_get_object<btk::Acquisition>(prhs[0]);
  btk::Analog::Pointer analog = btkMXGetAnalog(acq, nrhs, prhs);
  int numberOfFrames = analog->GetFrameNumber();
  if (mxGetNumberOfElements(prhs[2]) != numberOfFrames)
    mexErrMsgTxt("The third input doesn't have the same number of element than the number of analog frames.");
    
  double* values = mxGetPr(prhs[2]);
  for (int i = 0 ; i < numberOfFrames ; ++i)
    analog->GetValues().coeffRef(i) = values[i];
  
  // Return updated analog channels
  btkMXCreateAnalogsStructure(acq, nlhs, plhs);
};