AP-SCE/Mex/a611.cpp

47 lines
977 B
C++
Raw Normal View History

2018-01-06 16:17:50 +00:00
#include "mex.h"
#include "matrix.h"
#include "stdlib.h"
void mexFunction(int nlhs, mxArray *plhs[], // Output
int nrhs, const mxArray *prhs[]) // Input
{
2018-01-20 11:01:52 +00:00
if (nrhs != 3)
mexErrMsgTxt ("Check your input parameters");
if( mxGetNumberOfElements(prhs[1]) != mxGetNumberOfElements(prhs[2]))
{
mexErrMsgTxt ("arrays need to be of same size!");
}
2018-01-06 16:17:50 +00:00
int num_data_points = *mxGetPr(prhs[0]);
double* x = (double *)mxCalloc(num_data_points, sizeof(double));
double* y = (double *)mxCalloc(num_data_points, sizeof(double));
double* temp = (double *)mxCalloc(num_data_points, sizeof(double));
for(int j=0; j < num_data_points; j++)
{
x[j] = mxGetPr(prhs[1])[j];
y[j] = mxGetPr(prhs[2])[j];
}
//diff
for (int i=0; i < num_data_points; ++i)
{
temp[i] = y[i+1] - y[i];
}
// Output
2018-01-20 11:01:52 +00:00
nlhs = 1;
plhs[0] = mxCreateDoubleMatrix(1, num_data_points, mxREAL);
memcpy(mxGetPr(plhs[0]), temp, num_data_points*sizeof(double));
2018-01-06 16:17:50 +00:00
return;
}