MATLAB Answers

Changing function packaging of Simulink Functions to inlined

조회 수: 20(최근 30일)
Monika Jaskolka
Monika Jaskolka 2020년 7월 20일
답변: Jonas 2021년 5월 6일
Why is the Function Packaging option disabled for Simulink Functions? I'd like to edit this parameter to modify how the function is code-generated. I have Embedded Coder installed.
Here is an example of a very simple Simulink Function that does nothing, yet it is still generated as a function. Is it possible to force it to be inlined?


Fangjun Jiang
Fangjun Jiang 2020년 7월 20일
Inline would make that block a regular subsystem block, not a Simulink Function. A Simulink Function is called by its name, so I don't think there is any other way.
  댓글 수: 1
Monika Jaskolka
Monika Jaskolka 2020년 7월 20일
You can have inlined functions in C, so I think it would make sense to be able to generate inlined functions out of Simulink Functions.

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

Jonas 2021년 5월 6일
I have the same question. I want to inline a Simulink Function, but the option is disabled. However, when integrating a Simulink Function locally inside a Stateflow, I can inline the function successfully. Why is it not possible to inline a Simulink Function outside Stateflow charts?
Although I do not know why it is not possible, I have found a work-around for my use-case. Might be interesting for you.
Instead of using a Simulink Function, I have put the contents of the function as a subsystem in my library, checked 'Treat as Atomic unit' and then the option becomes available to force 'inline' for code generation.
If you want to use the block directly in your model, you just use the library block and it will be inlined. If you want to call the function by its name in a Stateflow chart, you use a local Simulink Function in the Stateflow chart and put the library block inside there. You can force inlining for the local Simulink Function in Stateflow.
The only caveat is that it is not possible to call the library block inside a MATLAB Function, because it requires a Simulink Function to do that. But for my application, I don't need it.

Community Treasure Hunt

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

Start Hunting!

Translated by