Neglection of [outport]variable generated for bus assignment block

6 ビュー (過去 30 日間)
Gowtham
Gowtham 2025 年 1 月 29 日
コメント済み: Gowtham 2025 年 1 月 31 日
My intention is to generate th code as mentioned below
void computeArea() {
rectangle.area = rectangle.length * rectangle.width;
}
  1 件のコメント
Gowtham
Gowtham 2025 年 1 月 29 日
Kindly let me know the solution as soon as possible.
I am hopeless!!!

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

回答 (2 件)

Akshat Dalal
Akshat Dalal 2025 年 1 月 30 日
編集済み: Akshat Dalal 2025 年 1 月 30 日
Hi Gowtham,
As per the image you attached and some guesswork, this could be because you're using virtual buses throughout the model. Virtual buses are just an graphical affordance to avoid cluttering the model and make it look cleaner. However, internally the member variables are considered as separate entities. You will have to use a non-virtual bus which actually treats the different variables as a single entity. You may refer the following documentations for more information:
Thanks
Akshat

Shivam Gothi
Shivam Gothi 2025 年 1 月 30 日
編集済み: Shivam Gothi 2025 年 1 月 30 日
hello @Gowtham,
As I do not have the simulink model, I tried to make a simple simulink model to reproduce the issue as shown below. I am also attaching it with this answer.
I was able to generate code that was of format:
void computeArea() {
rectangle.area = rectangle.length * rectangle.width;
}
You just need to do some optimisation setting under "Model Configurations -> Code Generation -> Optimisation:". I have done the following optimisation settings:
CASE-1: buid code for Generic real time (.grt)
below given are the optimisation settings:
The screen-shot of generated code is:
CASE-2: Build code for embedded real time (.ert)
below given are the optimisation settings:
The screenshot of generated code is:
I hope you find this useful !
  6 件のコメント
Gowtham
Gowtham 2025 年 1 月 31 日

Dear @Shivam Gothi Thank you for your response.I accept that the "out1"is created as object because of model design. But in order to get my intended code as multiplication of Rectangle.width and Rectangle. Length and storing in same bus object as Rectangle.area . How the model design need to be. Kindly help me out

Gowtham
Gowtham 2025 年 1 月 31 日

As per the requirement creation of out variable and assigning it as object is unnecessary.

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

カテゴリ

Help Center および File ExchangeNaming Conventions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by