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

c - mexcharactergiveinputintoparamaterpassprovideputs-functionsimulinkstring

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

Best Answer

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.