From 48c98cf6d2468f64cc72987ee4fe61ed4c9f9d69 Mon Sep 17 00:00:00 2001 From: Patrice Matz Date: Sat, 6 Jan 2018 17:17:50 +0100 Subject: [PATCH] -added 6.1.1 (diff function) --- Mex/a611.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ Mex/a611.m | 5 +++++ 2 files changed, 46 insertions(+) create mode 100644 Mex/a611.cpp create mode 100644 Mex/a611.m diff --git a/Mex/a611.cpp b/Mex/a611.cpp new file mode 100644 index 0000000..60251b8 --- /dev/null +++ b/Mex/a611.cpp @@ -0,0 +1,41 @@ +#include "mex.h" +#include "matrix.h" +#include "stdlib.h" + + + +void mexFunction(int nlhs, mxArray *plhs[], // Output + int nrhs, const mxArray *prhs[]) // Input +{ + + 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 + nlhs = num_data_points; + for(int j=0; j < num_data_points; j++){ + plhs[j]=mxCreateDoubleScalar(temp[j]); + } + + + + return; +} \ No newline at end of file diff --git a/Mex/a611.m b/Mex/a611.m new file mode 100644 index 0000000..9ca8244 --- /dev/null +++ b/Mex/a611.m @@ -0,0 +1,5 @@ +% function accepts 1 double and 2 vectors of double +% a611(#num_of_points, vector_a, vector_b) +% number of datapoints in both vectors must be equal, +% or else the result will not be correct +%