annotate DL/RLS-DLA/private/addtocols.c @ 65:55faa9b5d1ac

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