How to resolve code generation errors when Simulink functions have multiple instances

조회 수: 25 (최근 30일)

I am trying to generate code for a Simulink model where multiple model reference blocks refer to a single model. I would like to ask about the error I'm encountering. Below is the error message (some characters have been replaced):
Error:
Model 'model_xxxxxxxx', which is not an Export Function model, may not generate reusable code because it contains scoped Simulink function 'f_rand_yyyyy' which generates reusable code. Ensure that the model 'model_xxxxxxx' is an Export Function model to generate reusable code or Consider setting the model configuration parameter 'Code interface packaging' to 'Nonreusable function' and 'Total number of instances allowed per top model' to 'One'.
Recommended actions:
Consider setting the model configuration parameter 'Code interface packaging' to 'Nonreusable function'.
Consider setting the model configuration parameter 'Total number of instances allowed per top model' to 'One'.
① The referenced model uses a Simulink Function. Can I assume that is the cause of this error?
I referred to the following MATLAB documentation:
https://jp.mathworks.com/help/rtw/ug/code-generation-limitations-for-model-reference.html

채택된 답변

MathWorks Support Team
MathWorks Support Team 2025년 6월 18일
Yes, the error is likely caused by the referenced model including a Simulink Function. There are known limitations when using Simulink Functions in models that are referenced multiple times with the intention of generating reusable code.
Currently, it is not possible to achieve multi-instance behavior or function reuse when placing a Function Caller in the child model that calls a Simulink Function defined in the parent model.
However, this can be achieved by placing the Simulink Function within the referenced model itself, and calling it via a Function Caller inside that same model.
While users often intuitively define functions in the parent model, in scenarios like this, placing the function within the referenced model is the appropriate workaround.

추가 답변 (0개)

카테고리

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

태그

아직 태그를 입력하지 않았습니다.

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by