S-Function vector output without dimension defined
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Anushka
2025-6-20
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!
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!