mxCreateString usage when calling matlab
Mostrar comentarios más antiguos
I try to call a function from mex in matlab and for this reason I made a mxArray because the function has two inputs namely a first one which is text and the second one which is a number.
My function works when I have static text, but not when I want to use the input to the mex-function. In the latter case I only get the first letter and not all 49 characters so I assume there is a problem with the pointers but I seriously cannot figure out were the problem lies
working code:
mxArray *callInput[2];
double inputNumber;
....
callInput[0] = mxCreateString("StringBeingPassed");
callInput[1] = mxCreateDoubleScalar(inputNumber);
mexCallMATLAB(0,NULL,2, callInput,"functionName");
NOT working anymore (only first letter being passed to function):
mxArray *callInput[2], *stringMX;
char *string_pr;
char string[49];
double inputNumber;
....
stringMX = mxGetField(prhs[0],0,"string");
string_pr = mxGetData(stringMX);
for (ii=0;ii<49;ii++){
*(yearString+ii) = *(yearString_pr+ii);
}
callInput[0] = mxCreateString(string);
callInput[1] = mxCreateDoubleScalar(inputNumber);
mexCallMATLAB(0,NULL,2, callInput,"functionName");
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Write C Functions Callable from MATLAB (MEX Files) en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!