Can a variable length signal be converted to a fixed length signal?

5 views (last 30 days)
I start with a uint8 array. From this array I parse out both numeric and text values, but of course, the text values are actually uint8's since Simulink does not support strings.
The problem with parsing out the text values is that their length is variable, and as a result the signal resulting from this parsing contains a variable size array. The parsing is done in a MATLAB function block, which I guess prevents Simulink from inferring the size of the output signal.
A variable length signal would not be a problem if the s-function I wanted to give it to could receive a variable size array. Lastly, as a point of information, whatever I do MUST BE supported for code generation on a Raspberry Pi.
So I have two-questions:
  1. Am I missing something with s-functions and they CAN take variable size arrays as inputs?
  2. If I'm not missing something with s-functions, can the variable size signal be converted to a fixed size somehow, which would enable me to pass it to the s-function?
Regards,
Tyler

Answers (1)

Sanjana Ramakrishnan
Sanjana Ramakrishnan on 8 May 2017
S-Functions support variable size signals. Refer the below link for more information:
https://www.mathworks.com/help/simulink/ug/s-functions-using-variable-size-signals.html
  1 Comment
Walter Roberson
Walter Roberson on 8 May 2017
Also, the way to handle the variable length strings is to define a maximum string length; with the facilities described above, code can be generated to handle up to the defined maximum size.
Coding for truly unlimited strings is risky for hardware targetting, as you could end up asking for more memory than is available on the hardware; or even before that, you could end up exceeding the space that has been put aside for the stack. When you code for fixed array sizes, the compiler can (theoretically) construct call trees to determine the maximum stack usage, and adjust the stack / heap boundary point from that.
(I have not investigated to determine whether the Raspberry Pi grows the stack "upwards" or "downwards" so I am not certain how much of an issue stack placement is on the Raspberry Pi; it can certainly be important on some hardware targets.)

Sign in to comment.

Categories

Find more on Embedded Coder in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!