Can a Simulink function work with strings?
Afficher commentaires plus anciens
Hi! I'm trying to pass a string from workspace to Simulink, in case that it is possible, can a Simulink Function work with string variables?
Réponse acceptée
Plus de réponses (1)
Walter Roberson
le 25 Mai 2017
0 votes
If you are only using 8 bit characters, then you can uint8() the string and pass it as a byte vector. If you are using extended Unicode characters (for example Arabic or Chinese) then uint16() it rather than uint8(). Or you could double() the string... just not as efficient on memory.
You need to pay a bit of attention to whether the string is variable length or fixed length; fixed length is easier to deal with.
You cannot pass character vectors between blocks (unless perhaps as some form of custom signal?), but you can pass the byte values numerically and char() it inside MATLAB Function Blocks. If you do use uint8 then if you use a Serial Block and tell it to send uint8 then the receiver cannot tell the difference between that or having been sent "characters" since the serial receive just receive bytes either way.
Catégories
En savoir plus sur Simulink Functions dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!