Is there an example of how to pass a string as a paramater into a C-MEX S-function in Simulink?
6 views (last 30 days)
Show older comments
Is there an example of how to pass a string as a paramater into a C-MEX S-function in Simulink?
Accepted Answer
MathWorks Support Team
on 3 Feb 2010
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 Comments
More Answers (0)
See Also
Categories
Find more on String in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!