Effacer les filtres
Effacer les filtres

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

6 vues (au cours des 30 derniers jours)
huadian Xu
huadian Xu le 16 Fév 2017
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

Réponses (1)

Lucas Lebert
Lucas Lebert le 4 Juil 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

Catégories

En savoir plus sur Write C Functions Callable from MATLAB (MEX Files) dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by