How can enumerations be included in an s-function?
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am trying to convert a Simulink/ stateflow model to a black box. Using Matlab 2015a, right clicking on the subsystem - C/C++ code - Generate s-function will do the job but with one issue. I have some datatypes defined as enumeration via an m-file in the current folder. Is there an option to include these in the s-function so I dont need those enum m-files to run the s-function?
Thanks,
Martin
0 Kommentare
Antworten (1)
Varun Bhaskar
am 12 Aug. 2015
Hello,
You can use enumerated data type in C-MEX S-Function by defining same data type with MATLAB and S-Function.
To use enumerated data type in S-Function, you need to use ssRegisterTypeFromNamedObject method to resister the data type from MATLAB/Simulink into S-Function. Sample files can be downloaded below. To execute the model, execute following command first, and then simulate the model.
>>mex enumExample.c
In this case, we use the OnOff.m enumerated data type class for the registration. More on this S-function method can be found here:
More on creating these custom data types in MATLAB can be found here:
After the type is registered, you can use the "ssSetInputPortDataType" method to set the type accordingly:
if (ssGetSimMode(S) != SS_SIMMODE_SIZES_CALL_ONLY) {
DTypeId dataTypeIdReg;
ssRegisterTypeFromNamedObject(S, "OnOff", &dataTypeIdReg);
if (dataTypeIdReg == INVALID_DTYPE_ID)
return;
ssSetInputPortDataType(S, 0, dataTypeIdReg);
}
See example enumExample.c attached to know more about using enumerate data type in C-MEX S-Function.
Siehe auch
Kategorien
Mehr zu Prepare Model Inputs and Outputs finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!