Trouble building mex function from .c file
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Callen Brooks
le 16 Mar 2016
Commenté : Callen Brooks
le 16 Mar 2016
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 *' to
parameter 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 parameter
here
void 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!
0 commentaires
Réponse acceptée
James Tursa
le 16 Mar 2016
Modifié(e) : James Tursa
le 16 Mar 2016
Your prototype declares the first six arguments as double, not pointer_to_double:
void AircraftModel_(double, double, double,double, double, double, double *,double *,
double *, double *, double *, double*);
So you need to pass in doubles for these, not pointers. E.g. change your call to this (to dereference your input pointer_to_double variables to double variables):
AircraftModel_(j, *Swing, *Wspan, *FLength, *FDiameter, *Vel, GTOW, LoverD, BendStress, Range, Vstall, Climbrate);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Startup and Shutdown dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!