Wrong output value of Legacy Code Tool's Sfunction

时间:2017-07-10 15:29:14

标签: matlab simulink

enter image description here

I am getting wrong result of the example published in the Mathworks documentation in the link

I am expecting the output to be 2 times the sine wave of amplitude 1, but I am getting constant value of large magnitude in the order of 1e8.

I used the following commands:

def = legacy_code('initialize');
def.HeaderFiles = {'myfunc.h'};%,'mat.h'};
def.SourceFiles = {'myfunc.c'};
def.SFunctionName = 'sfun_myfunc';
def.OutputFcnSpec = 'double y1 = myfunc(double u1)';
def.Options.singleCPPMexFile = false;
legacy_code('sfcn_cmex_generate', def);
legacy_code('sfcn_tlc_generate', def);
legacy_code('compile', def);
legacy_code('slblock_generate', def);

What am I missing ?

1 个答案:

答案 0 :(得分:0)

我发现了问题。在头文件中,我错误地使用#ifdef而不是#ifndef。