comparison examples/private/addtocols.c @ 1:7750624e0c73 version0.5

(none)
author idamnjanovic
date Thu, 05 Nov 2009 16:36:01 +0000
parents
children
comparison
equal deleted inserted replaced
0:5181bee80bc1 1:7750624e0c73
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 }