MATLAB Answers

1

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

Asked by Fanny Benoist on 27 Feb 2018
Latest activity Answered by Nils Gerke on 31 Aug 2018
There is an example for c-MEX Sfunction but is there the same for C++ ?

  1 Comment

Sign in to comment.

1 Answer

回答者: 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"

  0 Comments

Sign in to comment.