Clear Filters
Clear Filters

strcat not supported for code generation simulink

25 views (last 30 days)
I have a need for a function block that can not be made with existing simulink blocks.
I built a very simply simulink model that uses a user defined function. aka a matlab typical .m function
inside there is the strcat function.
Im getting an error that says strcat not supported by code generation.
I have seen this time and time again not just with strcat but with basically anything.
Can anyone tell me what is going on? it seems as if you can basically use not "common" matlab features to build a simulink block
  1 Comment
Robert Scott
Robert Scott on 25 Aug 2021
I was able to get it working with strjoin.
I am unsure why simulink will not allow the use most of its basic functions

Sign in to comment.

Accepted Answer

Jonas on 25 Aug 2021
Edited: Jonas on 25 Aug 2021
See documentation for the MATLAB Function block. There it is mentioned that: "In addition to language restrictions, the MATLAB Function block supports a subset of the functions available in MATLAB. A list of supported functions is given in Functions and Objects Supported for C/C++ Code Generation." If you follow that link, you can find all supported functions (sorted by category or alphabetically), and strcat is not one of them.
Bottom line is, Simulink uses code generation and not all MATLAB functions are suitable for code generation.
If some functions you want to use are not supported in Simulink and they are in MATLAB, you are probably not using Simulink for the right task.

More Answers (1)

Walter Roberson
Walter Roberson on 25 Aug 2021
it seems as if you can basically use not "common" matlab features to build a simulink block
Yes, that is correct. Simulink is much more restricted than basic MATLAB is.
With regards to strcat:
  • if any input is a string object, the output is a string array. Sizes of non-scalar arguments must match and output is same size as the non-scalar input
  • if no input is a string object, but at least one input is a cell array of characters, the output is a cell array of characters. Sizes of non-scalar arguments must match, and output is same size as the non-scalar input
  • otherwise the output is a character array. The number of rows must match for entries with more than one row, and the output has that number of rows
So... in order for Simulink to be able to predict the size and data types of the outputs, it would have to know these rules and analyze the inputs. But if any of the inputs are passed in, then Simulink might not know the datatype ahead of time, and so be unable to statically decide size and datatype.
Simulink "string" signals also turn out not to be the same as character vectors or MATLAB string objects...
strjoin() on the other hand can predict that the output is character vector, always.
... and these differences are important in Simulink. MATLAB has the luxury of being able to dynamically change datatypes and size, but Simulink has no flexibility on changing data type, and a number of restrictions on changing size.
Simulink with acceleration is most targetted at configurations where you are not doing any dynamic memory allocation, or at most you have a restricted maximum call stack.


Find more on Programmatic Model Editing in Help Center and File Exchange




Community Treasure Hunt

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

Start Hunting!