Effacer les filtres
Effacer les filtres

strcat not supported for code generation simulink

18 vues (au cours des 30 derniers jours)
Robert Scott
Robert Scott le 25 Août 2021
Commenté : Robert Scott le 25 Août 2021
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 commentaire
Robert Scott
Robert Scott le 25 Août 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

Connectez-vous pour commenter.

Réponse acceptée

Jonas
Jonas le 25 Août 2021
Modifié(e) : Jonas le 25 Août 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.
  1 commentaire
Robert Scott
Robert Scott le 25 Août 2021
Thanks for pointing me to the list that is helpful

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 25 Août 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... https://www.mathworks.com/help/simulink/ug/simulink-strings.html
strjoin() on the other hand can predict that the output is character vector, always. https://www.mathworks.com/help/matlab/ref/strjoin.html
... 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.

Catégories

En savoir plus sur Simulink Coder dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by