Can a Simulink function work with strings?
显示 更早的评论
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?
采纳的回答
更多回答(1 个)
Walter Roberson
2017-5-25
0 个投票
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Simulink Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!