90 likes | 188 Views
Przykład zastąpienia m-pliku na C. Funkcja sqcum w m-pliku. Funkcja sqcum w C. #include <math.h> #include "mex.h" void mexFunction(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[]) { double *x, *y ; double sqsum ; int i, m, n, N ; if(nrhs != 1) {
E N D
Przykład zastąpienia m-pliku na C Funkcja sqcum w m-pliku
Funkcja sqcum w C #include <math.h> #include "mex.h" void mexFunction(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[]) { double *x, *y ; double sqsum ; int i, m, n, N ; if(nrhs != 1) { mexErrMsgTxt("SQCUM: Only one input argument allowed.") ; } if(nlhs != 1) { mexErrMsgTxt("SQCUM: Only one output argument allowed.") ; } m = mxGetM(prhs[0]) ; n = mxGetN(prhs[0]) ; if(((m > 1) && (n > 1)) || !mxIsDouble(prhs[0])) { mexErrMsgTxt("TRGtest: Only one dimension input vector allowed.") ; } N = m*n ; x = mxGetPr(prhs[0]); plhs[0] = mxCreateDoubleMatrix(1,N,mxREAL) ; y = mxGetPr(plhs[0],y) ; sqsum = x[0] ; y[0] = x[0] ; for(i = 1 ; i < N ; i++) { sqsum = sqsum - x[i]*(sqsum > 0 ? 1 : -1) ; y[i] = sqsum ; } }
Funkcja sqcum w C #include <math.h> #include "mex.h" void mexFunction(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[]) { double *x, *y ; double sqsum ; int i, m, n, N ; if(nrhs != 1) { mexErrMsgTxt("SQCUM: Only one input argument allowed.") ; } if(nlhs != 1) { mexErrMsgTxt("SQCUM: Only one output argument allowed.") ; } m = mxGetM(prhs[0]) ; n = mxGetN(prhs[0]) ; if(((m > 1) && (n > 1)) || !mxIsDouble(prhs[0])) { mexErrMsgTxt("TRGtest: Only one dimension input vector allowed.") ; } N = m*n ; x = mxGetPr(prhs[0]); plhs[0] = mxCreateDoubleMatrix(1,N,mxREAL) ; y = mxGetPr(plhs[0],y) ; sqsum = x[0] ; y[0] = x[0] ; for(i = 1 ; i < N ; i++) { sqsum = sqsum - x[i]*(sqsum > 0 ? 1 : -1) ; y[i] = sqsum ; } }
Funkcja sqcum w C #include <math.h> #include "mex.h" void mexFunction(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[]) { double *x, *y ; double sqsum ; int i, m, n, N ; if(nrhs != 1) { mexErrMsgTxt("SQCUM: Only one input argument allowed.") ; } if(nlhs != 1) { mexErrMsgTxt("SQCUM: Only one output argument allowed.") ; } m = mxGetM(prhs[0]) ; n = mxGetN(prhs[0]) ; if(((m > 1) && (n > 1)) || !mxIsDouble(prhs[0])) { mexErrMsgTxt("TRGtest: Only one dimension input vector allowed.") ; } N = m*n ; x = mxGetPr(prhs[0]); plhs[0] = mxCreateDoubleMatrix(1,N,mxREAL) ; y = mxGetPr(plhs[0],y) ; sqsum = x[0] ; y[0] = x[0] ; for(i = 1 ; i < N ; i++) { sqsum = sqsum - x[i]*(sqsum > 0 ? 1 : -1) ; y[i] = sqsum ; } }
Funkcja sqcum w C #include <math.h> #include "mex.h" void mexFunction(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[]) { double *x, *y ; double sqsum ; int i, m, n, N ; if(nrhs != 1) { mexErrMsgTxt("SQCUM: Only one input argument allowed.") ; } if(nlhs != 1) { mexErrMsgTxt("SQCUM: Only one output argument allowed.") ; } m = mxGetM(prhs[0]) ; n = mxGetN(prhs[0]) ; if(((m > 1) && (n > 1)) || !mxIsDouble(prhs[0])) { mexErrMsgTxt("TRGtest: Only one dimension input vector allowed.") ; } N = m*n ; x = mxGetPr(prhs[0]); plhs[0] = mxCreateDoubleMatrix(1,N,mxREAL) ; y = mxGetPr(plhs[0],y) ; sqsum = x[0] ; y[0] = x[0] ; for(i = 1 ; i < N ; i++) { sqsum = sqsum - x[i]*(sqsum > 0 ? 1 : -1) ; y[i] = sqsum ; } }