mxCreateString usage when calling matlab
显示 更早的评论
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");
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Write C Functions Callable from MATLAB (MEX Files) 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!