I have some old c code that someone made a while ago that I'm trying to use in a MATLAB project so I'm trying to convert the c functions to mex functions. I'm new to both c and mex functions, but I've managed to get the compiler installed (Xcode 7 on Mac OSX) and I've written what I thought would let me build the mex function, but I keep getting the following error:
Error using mex/C_GAmodel/GAmodel.c:108:22: error: passing 'double *' toparameter of incompatible type 'double'; dereference with * AircraftModel_(j,Swing, Wspan, FLength, FDiameter, Vel, GTOW, LoverD, BendStress, Range, Vstall, Climbrate); ^~~~~ */C_GAmodel/decfunc.h:3:35: note: passing argument to parameterherevoid AircraftModel_(double, double, double,double, double, double, double *,double *,double *, double *, double *, double*); ^1 error generated.
You can see in this error a line of code declaring the function AircraftModel_. The code I've written to try to generate the mex function is:
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){ /* Inputs */ double *Swing; double *Wspan; double *FLength; double *FDiameter; double *Vel; /* Outputs */ double *GTOW; double *LoverD; double *BendStress; double *Range; double *Vstall; double *Climbrate; int j; /* Swing= 14.3; // Wing area Wspan=10.5; // Wing Span FLength=8.22; // Fuselage Length FDiameter=1.5; // Fuselahge Diameter Vel=40.36; // Cruise Velocity */ j=0 ; // Calculates everything /* Check for proper number of arguments. */ if(nrhs!=5) { mexErrMsgIdAndTxt( "MATLAB:GAmodel:invalidNumInputs", "Five inputs required."); } else if(nlhs!=6) { mexErrMsgIdAndTxt( "MATLAB:GAmodel:maxlhs", "Six output arguments required."); } /* Create matrices for the return arguments. */ plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL); plhs[1] = mxCreateDoubleMatrix(1, 1, mxREAL); plhs[2] = mxCreateDoubleMatrix(1, 1, mxREAL); plhs[3] = mxCreateDoubleMatrix(1, 1, mxREAL); plhs[4] = mxCreateDoubleMatrix(1, 1, mxREAL); plhs[5] = mxCreateDoubleMatrix(1, 1, mxREAL); /* Assign pointers to each input and output. */ Swing = mxGetPr(prhs[0]); Wspan = mxGetPr(prhs[1]); FLength = mxGetPr(prhs[2]); FDiameter = mxGetPr(prhs[3]); Vel = mxGetPr(prhs[4]); GTOW = mxGetPr(plhs[0]); LoverD = mxGetPr(plhs[1]); BendStress = mxGetPr(plhs[2]); Range = mxGetPr(plhs[3]); Vstall = mxGetPr(plhs[4]); Climbrate = mxGetPr(plhs[5]); /* call the C subroutine */ AircraftModel_(j,Swing, Wspan, FLength, FDiameter, Vel, GTOW, LoverD, BendStress, Range, Vstall, Climbrate);
}
And the subroutine I'm trying to call is declared as:
void AircraftModel_( // Function to be evaluated double j, // design variables double Swing, double Wspan, double FLength, double FDiameter, double Vel, // system metrics double *GTOW, double *LoverD, double *BendStress, double *Range, double *Vstall, double *Climbrate ){<function body>}
Any help would be appreciated, thanks in advance!
Best Answer