annotate util/ksvd utils/addtocols.c @ 104:e2ce05e21a55

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