I'm creating a C++ mex function using the S-function builder option in simulink (matlab). I've successfully captured strings passed as a dialog box parameter in Simulink as:
Simulink block dialog:
Parameter : uint8('This is a string')
C++:
//Autogenerated part (mex.cpp)
#define PARAM_DEF0(S) ssGetSFcnParam(S, 0)
const int_T p_width0 = mxGetNumberOfElements(PARAM_DEF0(S));
const uint8_T *Parameter = (const uint8_T *) mxGetData(PARAM_DEF0(S));
//mex_wrapper.cpp
std::string Parameter_s(Parameter , Parameter + p_width0);
mexPrintf("Output String: %s", Parameter_s.c_str())
When running the program this produces the expected output: This is a string
.The problem arises when passing a 2d vector of uint8 (an array of strings).
I tried the following:
Simulink block dialog:
Parameter : uint8(['AAAA'; 'BBBB'])
C++:
//This part remains the same, because it is autogenerated,
//and paremeters have no dimension property in the builder at least (mex.cpp)
//...
#define PARAM_DEF0(S) ssGetSFcnParam(S, 0)
const int_T p_width0 = mxGetNumberOfElements(PARAM_DEF0(S));
const uint8_T *Parameter = (const uint8_T *) mxGetData(PARAM_DEF0(S));
//...
//mex_wrapper.cpp
//...
std::string Parameter_s(Parameter , Parameter + p_width0);
mexPrintf("Output String: %s", Parameter_s.c_str())
//...
The output in this case is : ABABABAB
. Is there a way to get the row dimension of parameters to avoid this behavior and correctly generalize for any size?