Can I modify how a native Simulink block is auto-coded?

2 ビュー (過去 30 日間)
Jeffrey
Jeffrey 2013 年 5 月 28 日
My Simulink model uses native Simulink blocks within multiple atomic subsystems that are defined as reusable functions with unique file names. When I auto-code my model, the native Simulink blocks get auto-coded as in-lined functions within the atomic subsystem's auto-generated function file. The problem comes when another atomic subsystem also uses this same native Simulink block, but, this time, the MATLAB Coder placed just a function call out to the code that is now in-lined within the other atomic subsystem's reusable function. This creates a dependency between the two subsystems' functions and the order in which they are compiled. Is there a setting either on the native Simulink block or within the model code generation configuration parameters that will allow me to specifify exactly how I want the native Simulink blocks to be auto-coded. I would like to have them coded as reusable functions within their own uniqe files which can be called by my other code.

採用された回答

Guy Rouleau
Guy Rouleau 2013 年 5 月 28 日
The Code Replacement Library seems to be what you are looking for. See this example:
  1 件のコメント
Jeffrey
Jeffrey 2013 年 5 月 29 日
It turned out that what I needed was even simpler than this suggestion, but, this suggestion lead me to the solution. By reading about this Code Replacement Library, I noticed that there is a setting within the Configuration Parameters Code Generation section where you can set the "shared code placement" to either "shared location" or "auto". By setting it to "shared location", all of the native Simulink blocks that were previously inlined within the parent functions were generated as static, stand-alone utility functions able to be shared and called by other functions.

サインインしてコメントする。

その他の回答 (1 件)

Valmir Sadiku
Valmir Sadiku 2013 年 5 月 28 日
編集済み: Valmir Sadiku 2013 年 5 月 28 日
One possible way to do that are:
  1. Right-Click on your subsystem -> select 'Block Parameter (Subsystem)'
  2. Select 'Treat as atomic unit'
  3. Go to the 'Code Generation' page and choose the 'Function packaging' as Reusable function.
hopefully this will help you.
  1 件のコメント
Jeffrey
Jeffrey 2013 年 5 月 28 日
Yes, that is how I have setup my subsystem blocks so that they are coded as reusuable functions. The problem I am having, however, is specifically with the "mod" native Simulink block within my subsystem blocks. The "Subsystem Parameters" option does not appear with the native Simulink blocks, therefore, I can not specify a reusable function name.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by