annotate Problems/private/addtocols.c @ 39:8f734534839a

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