How to pass a structure parameter in simulink mask to C mex S-Function?

6 次查看(过去 30 天)
Hello everyone,
I am using C mex S-Function to simulate in simulink and want to pass a structure parameter in Initialization Commands of Mask Editor to it.The structure parameter is here, e.g.:
CtrlPara.Kvp = 0.2;
CtrlPara.Kvi = 10 ;
CtrlPara.Kip = 0.1;
CtrlPara.Kii = 0 ;
I want C mex S-Function to access the parameter Kvp.Kvi,Kip and Kii. I found two commands,which may be helpful.They are following:
ssGetSFcnParam
mxGetField

回答(1 个)

Lucas Lebert
Lucas Lebert 2018-7-4
Hi Huadian!
I think you already have most of the information! In the mdlInitializeSizes callback method you need to set the Number of SFcnParameters,e.g: ssSetNumSFcnParams(S, 1);
Depending on where you want to use the fields of the Structure you can access these with the commands you mentioned, e.g:
const mxArray *param = mxGetField(ssGetSFcnParam(S,0),0,"Kvp");
real_T *value = mxGetPr(param);
Now you can use the pointer value for your further calculations.
Thanks! ~Lucas

类别

Help CenterFile Exchange 中查找有关 Write C Functions Callable from MATLAB (MEX Files) 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by