semen2006
Newbie level 2
![Newbie level 2](/styles/images/ranks/alevel2.gif)
MEX file for MATLAB
Why don`t its mex file in matlab? Help me? please.
/* function y = timestwo_alt(z,x,N) */
#include <math.h>
#include <stdio.h>
#include "mex.h"
void timestwo_alt(double *z, double *x, double y[], int N)
{
int i;
for(i=0; i<N; i++) {
y = *z*i+*x;
}
}
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
double *y;
double *z,*x;
int N, NN;
int mrows;
/*
mrows = mxGetM(plhs[0]);
y = mxGetPr(plhs[0]); */
/* NN=sizeof(*y);*/
/* Create a 1-by-1 matrix for the return argument. */
plhs[0] = mxCreateDoubleMatrix(N,1, mxREAL);
/* Get the scalar value of the input x. */
/* Note: mxGetScalar returns a value, not a pointer. */
x = mxGetPr(prhs[1]);
z = mxGetPr(prhs[0]);
N = mxGetScalar(prhs[2]);
/* NN = mxGetM(prhs[2]);
/* Assign a pointer to the output. */
y = mxGetPr(plhs[0]);
/* Call the timestwo_alt subroutine. */
timestwo_alt(z,x,y,N);
}
Why don`t its mex file in matlab? Help me? please.
/* function y = timestwo_alt(z,x,N) */
#include <math.h>
#include <stdio.h>
#include "mex.h"
void timestwo_alt(double *z, double *x, double y[], int N)
{
int i;
for(i=0; i<N; i++) {
y = *z*i+*x;
}
}
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
double *y;
double *z,*x;
int N, NN;
int mrows;
/*
mrows = mxGetM(plhs[0]);
y = mxGetPr(plhs[0]); */
/* NN=sizeof(*y);*/
/* Create a 1-by-1 matrix for the return argument. */
plhs[0] = mxCreateDoubleMatrix(N,1, mxREAL);
/* Get the scalar value of the input x. */
/* Note: mxGetScalar returns a value, not a pointer. */
x = mxGetPr(prhs[1]);
z = mxGetPr(prhs[0]);
N = mxGetScalar(prhs[2]);
/* NN = mxGetM(prhs[2]);
/* Assign a pointer to the output. */
y = mxGetPr(plhs[0]);
/* Call the timestwo_alt subroutine. */
timestwo_alt(z,x,y,N);
}