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

6 ビュー (過去 30 日間)
Is there an example of how to pass a string as a paramater into a C-MEX S-function in Simulink?

採用された回答

MathWorks Support Team
MathWorks Support Team 2010 年 2 月 3 日
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 Center および File ExchangeString についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by