Is there an example of how to pass a string as a parameter into a C++-MEX S-function in Simulink?

10 次查看(过去 30 天)
There is an example for c-MEX Sfunction but is there the same for C++ ?

回答(1 个)

Nils Gerke
Nils Gerke 2018-8-31
Here's a working example:
const mxArray* pArrayValue = ssGetSFcnParam(S,0);
const char* pCharArray = mxArrayToString(pArrayValue);
std::string string_1(pCharArray);
mexPrintf(string_1.c_str());
Make sure that you pass a char array as parameter in single quotes.
'Hello World'
not
"Hello World"

类别

Help CenterFile 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!

Translated by