matlab无法定义块,在simulink中运行用户定义的块时,Matlab崩溃

我在simulink中用单输入和单输出创建了一个用户定义的块,它工作得很好 . 但是当我在没有输入的情况下创建用户定义的块时,在simulink模型MATLAB Crashes中运行此块 . 下面是C S函数的代码 .

有关此的任何信息表示赞赏 .

#define S_FUNCTION_NAME My5times /* Defines and Includes */

#define S_FUNCTION_LEVEL 2

#include "simstruc.h"

static void mdlInitializeSizes(SimStruct *S)

{

ssSetNumSFcnParams(S, 2);

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

{

return; /* Parameter mismatch reported by the Simulink engine*/

}

if (!ssSetNumInputPorts(S, 0))

return;

ssSetInputPortWidth(S, 0, DYNAMICALLY_SIZED);

ssSetInputPortDirectFeedThrough(S, 0, 0);

if (!ssSetNumOutputPorts(S,1))

return;

ssSetOutputPortWidth(S, 0, DYNAMICALLY_SIZED);

ssSetNumSampleTimes(S, 1);

/* Take care when specifying exception free code - see sfuntmpl.doc */

ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE);

}

static void mdlInitializeSampleTimes(SimStruct *S)

{

ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME);

ssSetOffsetTime(S, 0, 0.0);

}

static void mdlOutputs(SimStruct *S, int_T tid)

{

int_T i;

/*int_T param = mxGetScalar(ssGetSFcnParam(S,0));*/

int_T buflen = mxGetN(ssGetSFcnParam(S, 0)) * sizeof(mxChar) + 1;

char_T* StringParam = mxMalloc(buflen);

int_T status = mxGetString(ssGetSFcnParam(S, 0), StringParam, buflen);

/* mexPrintf("The string being passed as a Paramater is - %s\n ", String);*/

/* InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S, 0);*/

real_T *y = ssGetOutputPortRealSignal(S, 0);

int_T width = ssGetOutputPortWidth(S, 0);

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

{

*y++ = 1;

}

}

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值