# urgent mexFunction()

hiiiiiiiiiiiiiii

i posted this in matlab part

anybody may help here as C++ programmers?????

below is my C++ function...cell.h will create a class cell of public attributes x,y, Freq and all are doubles....

ran will be generated in matlab to give a random number from a normal distribution

i want to have a correct output...

I believe the mexFunction() is not correct becoz am getting wrong answers although the algorithm is correct if implemented in matlab...and when i use mex to call this function it is working but it gave me:Command line warning D4002 : ignoring unknown option '-Oy-'

anyway i believe i didnt do the mexFunction() correctly especially at its end

plzzzz helppp me and thanks a lot

[code]

#include
#include
#include"cell.h"
#include "mex.h"
# define pi 3.14159265358979323846

void interference(double ran, double T,double ii,double Total,double f,double xp,double yp,double k,double M,double segma,double P)

{
double L;
L = 1+ 3*(T)*(T+1);//total number of cells determine the total number of elements in the Cell array

Cell* C= new Cell[L];

double I =0.0;
double Loss =0.0;

for(int i=1; i<= Total; i++)
{
if(i!=ii)
{
if(C[i].freq==f)
{

double d= sqrt(pow((1.0*xp-C[i].x),2) + pow((1.0*yp-C[i].y),2));
Loss= Loss + 10*log10(k) - 10*M*log10(d*pow(10,-3)) + segma*ran;
double I_db= 10*log10(P)+ Loss;
I= I+ pow(10,(I_db/10));

}

}

}

}

void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[] )
{
double *ran, *T,*ii, *Total,*f,*xp,*yp;
double *k;
double *M;
double *segma;
double *P;
mwSize mrows1,ncols1,mrows2,ncols2,mrows3,ncols3,mrows4,n
cols4,mrows5,ncols5,mrows6,ncols6,mrows7,ncols7,mr
ows8,ncols8,mrows9,ncols9,mrows10,ncols10,mrows11,
ncols11;

/* Check for proper number of arguments. */
if(nrhs!=11) {
mexErrMsgTxt("missing input required.");
} else if(nlhs>11) {
mexErrMsgTxt("Too many output arguments! need only 10");
}

/* The input must be a noncomplex scalar double.*/
mrows1 = mxGetM(prhs[0]);
ncols1 = mxGetN(prhs[0]);
if( !mxIsDouble(prhs[0]) || mxIsComplex(prhs[0]) ||
!(mrows1==1 && ncols1==1) ) {
mexErrMsgTxt("Input must be a noncomplex scalar double.");
}

mrows2 = mxGetM(prhs[1]);
ncols2 = mxGetN(prhs[1]);
if( !mxIsDouble(prhs[1]) || mxIsComplex(prhs[1]) ||
!(mrows2==1 && ncols2==1) ) {
mexErrMsgTxt("Input must be a noncomplex scalar double.");
}
mrows3 = mxGetM(prhs[2]);
ncols3 = mxGetN(prhs[2]);
if( !mxIsDouble(prhs[2]) || mxIsComplex(prhs[2]) ||
!(mrows3==1 && ncols3==1) ) {
mexErrMsgTxt("Input must be a noncomplex scalar double.");
}
mrows4 = mxGetM(prhs[3]);
ncols4 = mxGetN(prhs[3]);
if( !mxIsDouble(prhs[3]) || mxIsComplex(prhs[3]) ||
!(mrows4==1 && ncols4==1) ) {
mexErrMsgTxt("Input must be a noncomplex scalar double.");
}
mrows5 = mxGetM(prhs[4]);
ncols5 = mxGetN(prhs[4]);
if( !mxIsDouble(prhs[4]) || mxIsComplex(prhs[4]) ||
!(mrows5==1 && ncols5==1) ) {
mexErrMsgTxt("Input must be a noncomplex scalar double.");
}
mrows6 = mxGetM(prhs[5]);
ncols6 = mxGetN(prhs[5]);
if( !mxIsDouble(prhs[5]) || mxIsComplex(prhs[5]) ||
!(mrows6==1 && ncols6==1) ) {
mexErrMsgTxt("Input must be a noncomplex scalar double.");
}
mrows7 = mxGetM(prhs[6]);
ncols7 = mxGetN(prhs[6]);
if( !mxIsDouble(prhs[6]) || mxIsComplex(prhs[6]) ||
!(mrows7==1 && ncols7==1) ) {
mexErrMsgTxt("Input must be a noncomplex scalar double.");
}
mrows8 = mxGetM(prhs[7]);
ncols8 = mxGetN(prhs[7]);
if( !mxIsDouble(prhs[7]) || mxIsComplex(prhs[7]) ||
!(mrows8==1 && ncols8==1) ) {
mexErrMsgTxt("Input must be a noncomplex scalar double.");
}
mrows9 = mxGetM(prhs[8]);
ncols9 = mxGetN(prhs[8]);
if( !mxIsDouble(prhs[8]) || mxIsComplex(prhs[8]) ||
!(mrows9==1 && ncols9==1) ) {
mexErrMsgTxt("Input must be a noncomplex scalar double.");
}
mrows10 = mxGetM(prhs[9]);
ncols10 = mxGetN(prhs[9]);
if( !mxIsDouble(prhs[9]) || mxIsComplex(prhs[9]) ||
!(mrows10==1 && ncols10==1) ) {
mexErrMsgTxt("Input must be a noncomplex scalar double.");
}
mrows11 = mxGetM(prhs[10]);
ncols11 = mxGetN(prhs[10]);
if( !mxIsDouble(prhs[10]) || mxIsComplex(prhs[10]) ||
!(mrows11==1 && ncols11==1) ) {
mexErrMsgTxt("Input must be a noncomplex scalar double.");
}

/* Create matrix for the return argument. */
plhs[0] = mxCreateDoubleMatrix(mrows1,ncols1, mxREAL);
plhs[1] = mxCreateDoubleMatrix(mrows2,ncols2, mxREAL);
plhs[2] = mxCreateDoubleMatrix(mrows3,ncols3, mxREAL);
plhs[3] = mxCreateDoubleMatrix(mrows4,ncols4, mxREAL);
plhs[4] = mxCreateDoubleMatrix(mrows5,ncols5, mxREAL);
plhs[5] = mxCreateDoubleMatrix(mrows6,ncols6, mxREAL);
plhs[6] = mxCreateDoubleMatrix(mrows7,ncols7, mxREAL);
plhs[7] = mxCreateDoubleMatrix(mrows8,ncols8, mxREAL);
plhs[8] = mxCreateDoubleMatrix(mrows9,ncols9, mxREAL);
plhs[9] = mxCreateDoubleMatrix(mrows10,ncols10, mxREAL);
plhs[10] = mxCreateDoubleMatrix(mrows11,ncols11, mxREAL);

/* Assign pointers to each input and output. */
ran = mxGetPr(prhs[0]);
T = mxGetPr(prhs[1]);
ii = mxGetPr(prhs[2]);
Total = mxGetPr(prhs[3]);
f = mxGetPr(prhs[4]);
xp = mxGetPr(prhs[5]);
yp = mxGetPr(prhs[6]);
k = mxGetPr(prhs[7]);
M = mxGetPr(prhs[8]);
segma = mxGetPr(prhs[9]);
P = mxGetPr(prhs[10]);
/* Call the timestwo subroutine. */
interference(*ran,*T,*ii,*Total,*f,*xp,*yp,*k,*M,*
segma,*P);
}

[/code]

• What exactally is the algorithm that you are implementing?

Also, the code posted has alot of duplicate code and code that would be better implemented within loops...

I would like to help (Perhaps rewrite the routine), however dont know the algorithm you are trying to use so do not know what the correct results should be.