S-Function vector output without dimension defined

조회 수: 4 (최근 30일)
Luca
Luca 2025년 6월 18일
댓글: Luca 2025년 6월 20일
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

채택된 답변

Anushka
Anushka 2025년 6월 20일
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
Luca
Luca 2025년 6월 20일
Thank you so much, have a nice day.
Kind regards

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Coder에 대해 자세히 알아보기

태그

제품


릴리스

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by