MATLAB: Do I get an error when generating code from an Interpreted MATLAB Function block? And what is the difference between this block and a MATLAB Function block

codecustomizablefunctiongenerationintepretedMATLABsimulink

We have a model that consists of an Interpreted MATLAB Function block. When we tried to generate code from Simulink coder, we are receiving an error saying that:
Simulink Coder Error in block: "myModel/Interpreted MATLAB Function",
block type "MATLABFcn": Not yet supported by Simulink Coder
What is an alternative? What is the difference between MATLAB Function block and Interpreted MATLAB Function block?

Best Answer

This is expected since the Interpreted MATLAB Function block is not supported for code generation. To work around the issue, use a MATLAB Function block instead:
You can execute the following command at the MATLAB Command prompt to get the Block Support Table which displays the different blocks which are supported for Code generation:
>> showblockdatatypetable
There, it is mentioned to use the MATLAB Function block as an alternative to the Interpreted MATLAB Function block for code generation.
Differences between MATLAB Function and Interpreted MATLAB Function block:
The MATLAB Function block is compiled before run-time (R2014b and earlier, it generates C code and compiles; R2015a and later, it is compiled just-in time). The Interpreted MATLAB Function block uses the MATLAB interpreter to execute an existing MATLAB function.
If you're just running simulations on your desktop, there won't be much noticeable differences. However, if you're generating code from your model, you cannot do so with the Interpreted MATLAB Function block.
Also, the MATLAB Function block is a more customizable, as you have more control over the properties (size/data type/data scope) of all the variables, you can create tunable parameters in the blocks, etc.
In summary, the MATLAB Function block is much more flexible and we would recommend using it in most situations. The Interpreted MATLAB Function block can be easier to set up if you have already have an existing function, and it lets you use the full range of MATLAB as long as you're using the model strictly for desktop simulation.