MATLAB: Does the compilation of the model result in an error when using literal code symbols in an Action definition in Stateflow 6.0 (R14)

codeliteralstateflowsymbol [~]

The documentation regarding the use of literal code symbols in an Action statement says that the parser will ignore the lines between any $ characters. In my case, I have defined a statement with the following line:
$ read_memory; $
Even though the read_memory function is placed within literal code symbols, I cannot run my model. When I try, I receive the following error message:
Writing library for test_2006_01_31_sfun.mexw32
c1_test_2006_01_31.obj .text: undefined reference to '_read_memory'

Best Answer

This is expected behavior in Stateflow 6.0 (R14). While the parser does ignore the lines surrounded by '$' signs, the Stateflow model still has to be translated into C code before the model is run. Therefore, the function read_memory still has to be defined.
This function definition has to be passed to the compiler via the Stateflow S-Function target options. More information on including custom code into Stateflow can be found in the documentation under "Integrating Custom Code with Stateflow Targets". This can be accessed by entering the following at the MATLAB Command Prompt:
web([docroot,'/toolbox/stateflow/ug/f1-1026868.html'])
It is good practice to avoid using literal code symbols in Stateflow whenever possible. Instead, it is better to directly implement C code into a Stateflow model. By using this approach instead of literal code symbols, you have the ability to pass inputs and outputs directly to your C code.