c语言mexfunction函数改参数,C_MEX s函数的参数设置问题

#define S_FUNCTION_NAME  filter1

#define S_FUNCTION_LEVEL 2

#include "simstruc.h"

#define COEF_IDX 0

#define COEF(S) mxGetScalar(ssGetSFcnParam(S,COEF_IDX))

static void mdlInitializeSizes(SimStruct *S)

{

ssSetNumSFcnParams(S, 1);  /* Number of expected parameters */

if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {

/* Return if number of expected != number of actual parameters */

return;

}

if (!ssSetNumInputPorts(S, 1)) return;

ssSetInputPortWidth(S, 0, DYNAMICALLY_SIZED);

ssSetInputPortRequiredContiguous(S, 0, 1); /*direct input signal access*/

ssSetInputPortDirectFeedThrough(S, 0, 1);

if (!ssSetNumOutputPorts(S, 1)) return;

ssSetOutputPortWidth(S, 0, DYNAMICALLY_SIZED);

ssSetNumSampleTimes(S, 1);

ssSetNumDWork(S, 1);

/* Specify the sim state compliance to be same as a built-in block */

ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE);

ssSetOptions(S,

SS_OPTION_WORKS_WITH_CODE_REUSE |

SS_OPTION_EXCEPTION_FREE_CODE |

SS_OPTION_USE_TLC_WITH_ACCELERATOR);

}

static void mdlInitializeSampleTimes(SimStruct *S)

{

ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME);

ssSetOffsetTime(S, 0, 0.0);

ssSetModelReferenceSampleTimeDefaultInheritance(S);

}

#define MDL_INITIALIZE_CONDITIONS   /* Change to #undef to remove function */

#if defined(MDL_INITIALIZE_CONDITIONS)

static void mdlInitializeConditions(SimStruct *S)

{

real_T *x = (real_T*)ssGetDWork(S,0);

x[0] = 0.0;

}

#endif /* MDL_INITIALIZE_CONDITIONS */

#define MDL_START  /* Change to #undef to remove function */

#if defined(MDL_START)

static void mdlStart(SimStruct *S)

{

}

#endif /*  MDL_START */

static void mdlOutputs(SimStruct *S, int_T tid)

{

int_T i;

InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0);

real_T *y = ssGetOutputPortRealSignalPtrs(S,0);

int_T width = ssGetOutputPortWidth(S,0);

real_T *x = (real_T *)ssGetDWork(S,0);

real_T Lc = 0.05;

for(i = 0; i< width; i++)

{

y[i]=(*uPtrs[i] - x[i]) * Lc + x[i];

}

for(i = 0; i< width; i++)

x[i] = y[i];

}

#define MDL_UPDATE  /* Change to #undef to remove function */

#if defined(MDL_UPDATE)

static void mdlUpdate(SimStruct *S, int_T tid)

{

}

#endif /* MDL_UPDATE */

#define MDL_DERIVATIVES  /* Change to #undef to remove function */

#if defined(MDL_DERIVATIVES)

static void mdlDerivatives(SimStruct *S)

{

}

#endif /* MDL_DERIVATIVES */

static void mdlTerminate(SimStruct *S)

{

}

#ifdef  MATLAB_MEX_FILE    /* Is this file being compiled as a MEX-file? */

#include "simulink.c"      /* MEX-file interface mechanism */

#else

#include "cg_sfun.h"       /* Code generation registration function */

#endif

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值