The reason for the error is that there is a dynamically sized array in the MATLAB Function block that depends on a tunable input parameter. In the example the array "B" is equal to "ones(A)" where "A" is a tunable input parameter. Because "A" is unknown at compile-time, the size of "B" is also unknown at compile-time and thus we cannot statically allocate memory for "B". Even if you define a max size for "B" using "coder.varsize", there is no guarantee that "A" will be less than the maximum size for "B", thus the error persists.
Here are three potential workaround to this problem:
1. If you do not need the parameter "A" to be tunable, then you can make "A" non-tunable by un-checking the "Tunable" checkbox for "A" in the "Ports and Data Manager". Now we can check for the size of "B" at compile-time. This will remove the error. To learn more about ports and data manager, execute the following command in the MATLAB R2018b command window:
web(fullfile(docroot, 'simulink/ug/_bqgwvsq-1.html'));
2. You can also add an "assert" statement that can be used to enforce the max size of "B" and thus the "B" will be statically allocated at its maximum size. For example, add the following line to the MATLAB Function block code:
3. You can specify the variable sized arrays to be dynamically allocated, thus you do not need to know their size at compile-time because they will be set at run-time. You can do this by turning on "Dynamic Memory Allocation in MATLAB Functions" in the configuration parameters. Also by setting the "Dynamic Memory Allocation Threshold in MATLAB Functions" to "0", it can guarantee that all variable sized arrays will be dynamically allocated. See following link for more details:
Please follow the below link to search for the required information regarding the current release: