annotate examples/private/addtocols.c @ 5:f44689e95ea4

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