MATLAB: Problems with Code Generation

code generationmatlab codermatlab functions-functionsimulink

Hello all, let me present you my problems with Code Generation and ask you for help or tips. I use Matlab R2013a.
Originally I have one control scheme, but here I attached just the parts which are causing the problems. The goal is to build the Simulink scheme which can be built with Code Generation to C code (for C module on PLC).
Everything in the scheme is built of Simulink blocks, except one function Fuzzyfication, which I’m trying to implement with Matlab Function (which should be OK for Code Generation). If you look at the initialize_extf_w_test.m file, it is just loading/initializing some parameters and simulating the Simulink scheme, where only Fuzzyfication Matlab Function is running.
But this scheme cannot be run, I get the error “Errors occurred during parsing of MATLAB function 'MATLAB Function'(#875)”. I don’t know if number is important, because they are sometimes different, but I also cannot find what it would mean. On the other hand, if I move the function to .m file (fuzzycation.m) and run “codegen fuzzyfication”, it works fine and it builds the C code. Also, if I implement the same code in the level 2 S-function and run the scheme (it is not attached), it works fine.
So, my question is, what could be wrong with running this in Matlab Function? What I’m missing? I know the implementation could be done with C-S functions, but I’m trying to avoid that (Matlab function should be also OK), due to lack of experience in plain C coding.
Thank you for answers, tips, help, etc. in advance. Best regards,

Best Answer

the answer here is, you must run this with button from Simulink, the pop-up is shown and shows the errors, which then are easily solved.