1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| #include "mex.h"
#include "matrix.h"
#include "fintrf.h"
void calcul (double *x, double *z,int n)
{
int i,j,k;
double temp;
double *b;
b=x;
for (i=1;i++;i<=n){
z[i]=0;
for (j=1;j++;j<=n){
z[i]=z[i]+x[j]*b[j];
}
temp=b[n];
for (k=1;k++;k<=n-1){
b[n-k+1]=b[n-k];
}
b[1]=temp;
}}
/* The gateway function */
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
/* variable declarations here */
double *inMatrix; /* 1xN input matrix */
int ncols; /* size of matrix */
double *outMatrix; /* output matrix */
/* code here */
if(nrhs!=1) {
mexErrMsgIdAndTxt("MyToolbox:arrayProduct:nrhs",
"one inputs required.");
}
if(nlhs!=1) {
mexErrMsgIdAndTxt("MyToolbox:arrayProduct:nlhs",
"one output required.");
}
/* create a pointer to the real data in the input matrix */
inMatrix = mxGetPr(prhs[0]);
/* get dimensions of the input matrix */
ncols = mxGetN(prhs[0]);
/* create the output matrix */
plhs[0] = mxCreateDoubleMatrix(1,ncols,mxREAL);
/* get a pointer to the real data in the output matrix */
outMatrix = mxGetPr(plhs[0]);
calcul(inMatrix,outMatrix,ncols);
} |
Partager