필터 지우기
필터 지우기

Can a Simulink function work with strings?

조회 수: 14 (최근 30일)
celia muñoz
celia muñoz 2017년 5월 22일
댓글: Walter Roberson 2017년 5월 26일
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?

채택된 답변

David Ding
David Ding 2017년 5월 25일
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
David Ding
David Ding 2017년 5월 26일
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
Walter Roberson 2017년 5월 26일
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?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2017년 5월 25일
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.

Community Treasure Hunt

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

Start Hunting!

Translated by