How to generate RTW file programmatically?

3 ビュー (過去 30 日間)
Soham Sinha
Soham Sinha 2022 年 1 月 29 日
コメント済み: Mark McBroom 2022 年 2 月 1 日
Is there any API to generate only the rtw file programmatically for a subsystem or a model?
For example, slbuild builds the entire model or a subsystem. Is there any way to just generate the model.rtw or subsystem.rtw.
Also is there any way to just generate code for a particular subsystem or a model, and not try to build the entire model itself?
It seems like %include "codegenentry" does this. However, I found no programmatic (in matlab) way to call this on a subsystem or model. Only interface is the slbuild which builds the entire model including compilation of the generated code.

回答 (1 件)

Mark McBroom
Mark McBroom 2022 年 1 月 29 日
slbuild() can be used to generate code for a subsystem:
% open example model
rtwdemo_rtwintro
%generate code for subsystem
slbuild('rtwdemo_rtwintro/Amplifier')
  2 件のコメント
Soham Sinha
Soham Sinha 2022 年 2 月 1 日
But slbuild is prohibited to be called recursively. So if I am compiling a top model, I cannot compile a subsystem independently.
I don't even want to compile the whole model or the subsystem as well. I just want to generate the respective code for a subsystem. Is there any API just for code generation, not building the entire subsystem/model?
Mark McBroom
Mark McBroom 2022 年 2 月 1 日
No, it is not possible to build/update/genereate code only for a subsystem. This is because Simulink needs to understand the context in which the subsystem is being used ( rates, data types, sizes, etc) before code can be generated. If you want code only for a subsystem, you will need to place into a seperate model and reference that model from the parent model. You can then use the following slbuild option to only generate code for the referenced model:
slbuild(<modelname>,"ModelReferenceCoderTargetOnly")

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

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by