Add simscape blocks programmatically

24 ビュー (過去 30 日間)
Grzegorz Diaczek
Grzegorz Diaczek 2022 年 12 月 20 日
回答済み: Salman 2025 年 11 月 14 日 22:25
Hello,
I tried to add a simscape block programmatically, using 'add_block()' function.
add_block('Simscape/Foundation Library/Electrical/Electrical Sources/Controlled Current Source',[gcb,'/Current Load'])
The following error occured:
There is no block named 'Simscape/Foundation Library/Electrical/Electrical Sources/Controlled Current Source'
I check if there is no mistake in path definition, also the simulink and simscape has been loaded using 'load_system()' function. Using simple command to built-in library works fine:
add_block('built-in/Gain',[gcb,'/Current Load'])
Thanks for help.
  1 件のコメント
Mana
Mana 2025 年 2 月 21 日
I have the same problem and have not found a solution. I am interested if you know the solutions.

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

回答 (2 件)

Chetan Bhavsar
Chetan Bhavsar 2022 年 12 月 20 日
  1 件のコメント
Grzegorz Diaczek
Grzegorz Diaczek 2022 年 12 月 20 日
Thank you for your answer. Unfortunately, the output of gcb when block is right clicked in Library Browser is empty.

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


Salman
Salman 2025 年 11 月 14 日 22:25
Here is the definite solution
⑴ Manually import the Simscape block into Simscape Model
⑵ Select the Model and then go to command line and enter the following
  • gcb
⑶ Dont bother what it gives you. But it must give you something like
  • 'my_model/Solver Configuration'
⑷ Next use the following Command
  • get_param(gcb, 'ReferenceBlock')
⑸ I got the following output, so should you.
  • ans = 'nesl_utility/Solver Configuration'
⑹ This gives us everything we need.
⑺ Instead of using add_block('Simscape/..., use the following command
  • add_block('nesl_utility/Solver Configuration', [model '/Solver Configuration 1']);
⑻ The End 🤓

カテゴリ

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

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by