diff options
Diffstat (limited to 'SD-VBS/common/toolbox/mex_template.c')
-rwxr-xr-x | SD-VBS/common/toolbox/mex_template.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/SD-VBS/common/toolbox/mex_template.c b/SD-VBS/common/toolbox/mex_template.c new file mode 100755 index 0000000..b85683f --- /dev/null +++ b/SD-VBS/common/toolbox/mex_template.c | |||
@@ -0,0 +1,58 @@ | |||
1 | //function W = mex_template(X,Y); | ||
2 | |||
3 | #include <math.h> | ||
4 | #include <mex.h> | ||
5 | //#include <matrix.h> | ||
6 | //#include "mex_util.cpp" | ||
7 | |||
8 | //#define PI 3.1415927 | ||
9 | |||
10 | void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray | ||
11 | *in[]) { | ||
12 | //reading in | ||
13 | const mxArray *X = in[0]; | ||
14 | double *pr = mxGetPr(X); | ||
15 | int *ir = mxGetIr(X); | ||
16 | int *jc = mxGetJc(X); | ||
17 | int m = mxGetM(X); | ||
18 | int n = mxGetN(X); | ||
19 | |||
20 | mxArray *cell_1 = mxGetCell(cell_input,0); | ||
21 | mxGetData() | ||
22 | mxGetNumberOfDimensions() | ||
23 | mxGetDimensions() | ||
24 | mxGetNumberOfElements() | ||
25 | |||
26 | //sparse array reading | ||
27 | int i,j,k; | ||
28 | double x; | ||
29 | for (j=0;j<n;j++) | ||
30 | for (k=jc[j]; k!=jc[j+1]; k++) { | ||
31 | i = ir[k]; | ||
32 | x = pr[k]; | ||
33 | //x = X(i,j); | ||
34 | } | ||
35 | |||
36 | //printing variables & debugging | ||
37 | int nnz = jc[n]; | ||
38 | mexPrintf("nnz = %d\n",nnz); | ||
39 | double z = 0.15; | ||
40 | mexPrintf("z = %1.3g \n",z); | ||
41 | mexErrMsgTxt("Stopped\n"); | ||
42 | |||
43 | //common functions | ||
44 | fabs(x) // absolute value of float x | ||
45 | |||
46 | //writing out | ||
47 | mxArray *W = mxCreateSparse(m, n, nnz, mxREAL); | ||
48 | |||
49 | |||
50 | mxArray *args[2]; | ||
51 | args[0] = (mxArray*) prhs[0]; | ||
52 | args[1] = mxCreateDoubleScalar(2.0); | ||
53 | mexCallMATLAB(1, plhs, 2, args, "sum"); | ||
54 | |||
55 | //allocating, desallocating | ||
56 | int *ind = (int*)mxCalloc(n,sizeof(int)); | ||
57 | mxFree(ind); | ||
58 | } \ No newline at end of file | ||