Mercurial > hg > smallbox
comparison util/ksvd utils/addtocols.c @ 70:c3eca463202d
(none)
author | idamnjanovic |
---|---|
date | Wed, 16 Mar 2011 14:16:57 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
69:5f1f436057ca | 70:c3eca463202d |
---|---|
1 /************************************************************************** | |
2 * | |
3 * File name: addtocols.c | |
4 * | |
5 * Ron Rubinstein | |
6 * Computer Science Department | |
7 * Technion, Haifa 32000 Israel | |
8 * ronrubin@cs | |
9 * | |
10 * Last Updated: 19.4.2009 | |
11 * | |
12 *************************************************************************/ | |
13 | |
14 | |
15 #include "mex.h" | |
16 | |
17 | |
18 /* Input Arguments */ | |
19 | |
20 #define X_IN prhs[0] | |
21 #define V_IN prhs[1] | |
22 | |
23 | |
24 /* Output Arguments */ | |
25 | |
26 #define Y_OUT plhs[0] | |
27 | |
28 | |
29 void mexFunction(int nlhs, mxArray *plhs[], | |
30 int nrhs, const mxArray*prhs[]) | |
31 | |
32 { | |
33 double *x, *y, *v, *xend; | |
34 mwSize m,n,m1,n1; | |
35 mwIndex counter; | |
36 | |
37 | |
38 /* Check for proper number of arguments */ | |
39 | |
40 if (nrhs != 2) { | |
41 mexErrMsgTxt("Two input arguments required."); | |
42 } else if (nlhs > 1) { | |
43 mexErrMsgTxt("Too many output arguments."); | |
44 } | |
45 | |
46 | |
47 /* Check the the input dimensions */ | |
48 | |
49 m = mxGetM(X_IN); | |
50 n = mxGetN(X_IN); | |
51 if (!mxIsDouble(X_IN) || mxIsComplex(X_IN) || mxGetNumberOfDimensions(X_IN)>2) { | |
52 mexErrMsgTxt("ADDTOCOLS requires that X be a double matrix."); | |
53 } | |
54 m1 = mxGetM(V_IN); | |
55 n1 = mxGetN(V_IN); | |
56 if (!mxIsDouble(V_IN) || mxIsComplex(V_IN) || (m1!=1 && n1!=1)) { | |
57 mexErrMsgTxt("ADDTOCOLS requires that V be a double vector."); | |
58 } | |
59 if ((m1==1 && n1!=n) || (n1==1 && m1!=n)) { | |
60 mexErrMsgTxt("Error in ADDTOCOLS: dimensions of V and X must agree."); | |
61 } | |
62 | |
63 | |
64 /* Create a matrix for the return argument */ | |
65 Y_OUT = mxCreateDoubleMatrix(m, n, mxREAL); | |
66 | |
67 | |
68 /* Assign pointers to the various parameters */ | |
69 x = mxGetPr(X_IN); | |
70 v = mxGetPr(V_IN); | |
71 y = mxGetPr(Y_OUT); | |
72 | |
73 | |
74 /* Do the actual computation */ | |
75 | |
76 xend = x+(m*n); | |
77 counter = 0; | |
78 while (x<xend) { | |
79 (*y) = (*x) + (*v); | |
80 y++; x++; counter++; | |
81 if (counter==m) {v++; counter=0;} | |
82 } | |
83 | |
84 return; | |
85 } |