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

6 次查看(过去 30 天)

采纳的回答

MathWorks Support Team
There is an example showing of how to pass a string as a paramater into a C-MEX S-function. You can find the files linked below.
If you open up the S-function source file, you will notice the following lines in mdlOutputs:
buflen = mxGetN((ssGetSFcnParam(S, 3)))*sizeof(mxChar)+1;
String = mxMalloc(buflen);
status = mxGetString((ssGetSFcnParam(S, 3)), String,buflen);
mexPrintf("The string being passed as a Paramater is - %s\n ", String);
Here the first two lines allocate memory for the string that is being passed into the S-function. Then you would use mxGetString to store this string in a character array. In this example the parameter is being stored in a char * called "String". The parameter "buflen" will be the length of this string.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 String 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by