How to set Simulink block parameter equal to the value of a signal?

7 ビュー (過去 30 日間)
Davide Fasciani
Davide Fasciani 2021 年 11 月 23 日
I have a tcp client in the subsystem and I would like to set the ip and port value, according to the subsystem input signals. In this way, I would be able to configure my client directly through the input signals. It's something possible?

回答 (1 件)

Harikrishnan Balachandran Nair
Harikrishnan Balachandran Nair 2021 年 12 月 2 日
編集済み: Harikrishnan Balachandran Nair 2021 年 12 月 2 日
Hi Davide,
I understand that you are trying to change the block parameters of a certain block, during simulation, depending on the value of the input signal.
This is achievable using the 'set_param' function in matlab. 'set_param' function can be used to set the block parameter values programmatically. You can have a 'matlab function' block in your model ,prior to the subsytem , inside which you can execute the 'set_param' function to set the block parameter values according to your need.
However , it is not considered a best practice to change the block parameter values during runtime. You can refer to this article to get a better understanding on this : https://blogs.mathworks.com/simulink/2011/03/08/how-do-i-change-a-block-parameter-based-on-the-output-of-another-block/
  2 件のコメント
Davide Fasciani
Davide Fasciani 2021 年 12 月 6 日
Thanks for the reply, I tried to follow your suggestions, but simulink gave me an error "Function 'set_param' not supported for generating the code."
Harikrishnan Balachandran Nair
Harikrishnan Balachandran Nair 2021 年 12 月 7 日
You may include the following line of code to avoid this error.
coder.extrinsic('set_param');
Hope this helps.

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

カテゴリ

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

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by