Can a Simulink function work with strings?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
celia muñoz
le 22 Mai 2017
Commenté : Walter Roberson
le 26 Mai 2017
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?
0 commentaires
Réponse acceptée
David Ding
le 25 Mai 2017
Hi Celia,
Unfortunately it is not possible for any Simulink block to accept a string variable. Simulink is used for generating numeric outputs for a model based on the numeric inputs of the model in the previous time step plus the time step size multiplied by the derivative of the model. Clearly, there is no way to perform arithmetic operations or take the derivative of a string variable.
Thanks,
David
3 commentaires
David Ding
le 26 Mai 2017
Hi Walter,
I should have clarified. If Celia is meaning to ask if one can pass string variables between blocks, the answer would be no. Serial blocks and TCP blocks that work with uint8 data would otherwise be different.
Thanks,
David
Walter Roberson
le 26 Mai 2017
Let me phrase it this way:
If I have a discrete model and at some point it calculates a block output to be uint8 [104 101 108 108 111], and that block is connected to another block with matching data types, then is it ever the case that the second block will receive something that is not bitwise identical to uint8 [104 101 108 108 111] ?
Other, that is, then perhaps a From Workspace or From File source block whose behaviour has been set to "interpolate".
Likewise for continuous models: if I have a MATLAB Function block or Level II Function block or even Arithmetic block which calculates uint8 [104 101 108 108 111] then can it ever be received by the next block as something that is not bitwise the same?
Plus de réponses (1)
Walter Roberson
le 25 Mai 2017
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.
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!