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,

3 Comments

AFAIK, the number (#875) is just an ID assigned to that specific MATLAB Function block. There are typically additional error messages that show up on the pop-up error window. Do you see any messages other than the one you posted? You may also want to scroll down and read the complete message to make sure you're not missing anything.
everything I got, running this from m-script, was:
>> initialize_extf_w_test Errors occurred during parsing of MATLAB function 'MATLAB Function'(#913)
Code Directory : "C:\Users\preglej\Desktop\lolimot-au\working\matlabfcn\central\slprj\_sfprj\MIMO_5x5_w_extf_same_tst\_self\sfun\src"
Machine (#912): "MIMO_5x5_w_extf_same_tst" Target : "sfun"
Chart "MATLAB Function" (#913):
. Code generation failed Errors occurred during parsing of MATLAB function 'MATLAB Function'(#913)
Error using initialize_extf_w_test (line 40) Errors occurred during parsing of MATLAB function 'MATLAB Function'(#913)
>>
and also no pop-up window was shown. but when you run this with button from Simulink, the pop-up is shown and shows the errors, which I didn't know.
now, when I saw the error, it was no problem to solve it.
I will see now if my whole scheme will work.
thank you (for now) and best regards
I have another question, is there any possibility to have "Initialize" routine in the Matlab Function block (like in the S-function)?
I know that there is IC block, but maybe some other options?

Sign in to comment.

 Accepted Answer

Aleksander Preglej
Aleksander Preglej on 7 Oct 2013
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.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!