S-Function vector output without dimension defined

3 vues (au cours des 30 derniers jours)
Luca
Luca le 18 Juin 2025
Commenté : Luca le 20 Juin 2025
Hi all.
My question is:
Is it possible somehow define an output interface to generate a "C" S-Function with an output as vector with the dimension not defined?
For ex. if i defined
def.OutputFcnSpec=['void fc_MyFunc (int16 u1, uint8 u2[], y1[])'];
is not possible for y1 not indicate the dimension for my knowledge, it must define y1[dimension-vector] and not as possible for input u2[]
When i launch the
legacy_code('sfcn_cmex_generate', def);
an error is reported.
I found a very cumbersome way to do it manually, but I wanted to understand if there is a way to do it automatically through some particular semantics or command that I do not know.
My ultimate goal is to have a mex file to use as a Simulink block for the library usage of my SW component.
Thank you in advance,
LuLa

Réponse acceptée

Anushka
Anushka le 20 Juin 2025
Hi @Luca,
It is not possible to define an output (‘y1[]’) with undefined or variable dimension in the ‘OutputFcnSpec’ when using ‘legacy_code’ with 'sfcn_cmex_generate'. Unlike inputs, output dimensions must be explicitly defined in the function signature (e.g., ‘y1[10]’), because Simulink requires fixed output dimensions for S-Functions at compile time.
You can try the following workarounds:
1. You can use manual modification after code generation (as you mentioned).
2. You can use “mdlInitializeSizes” in a hand-written wrapper ‘S-Function’ to set output dimensions dynamically but this is not automated via ‘legacy_code’.
You can refer to the following documentation of “mdInitializeSizes” for a better understanding: https://in.mathworks.com/help/simulink/sfg/mdlinitializesizes.html
Hope this helps!
  1 commentaire
Luca
Luca le 20 Juin 2025
Thank you so much, have a nice day.
Kind regards

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Simulink Coder dans Help Center et File Exchange

Tags

Produits


Version

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by