Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
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

Risposte (1)

Lucas Lebert
Lucas Lebert il 4 Lug 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

Categorie

Scopri di più su Write C Functions Callable from MATLAB (MEX Files) in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by