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

8 Ansichten (letzte 30 Tage)
huadian Xu
huadian Xu am 16 Feb. 2017
Beantwortet: Lucas Lebert am 4 Jul. 2018
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

Antworten (1)

Lucas Lebert
Lucas Lebert am 4 Jul. 2018
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

Kategorien

Mehr zu Write C Functions Callable from MATLAB (MEX Files) 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!

Translated by