How to change const variable during simulink runtime

17 ビュー (過去 30 日間)
Jack Daniels
Jack Daniels 2025 年 1 月 22 日
編集済み: Fangjun Jiang 2025 年 1 月 22 日
Hi,
I would like to change the value of a constant ("Mec_initial_pos") on simulink during runtime when simulations runs.
The value of "Mec_initial_pos" is initialized before Simulink run and I need to change the vsrialble wich is within constant block.

回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2025 年 1 月 22 日
編集済み: Fangjun Jiang 2025 年 1 月 22 日
While the simulation is running, if you double click the Constant block, change its value from one numeric value to another (e.g. from 1 to 2) and hit return, it will take effect immediately.
For a variable constant, there is one trick. Double click the Constant block so it shows the varialbe name. The numeric value is also displayed on the right. Go to MATLAB Command Window, change the value of the variable. Then at the Constant block dialog, you need to do some trivial change such as adding a whitespace at the end of the variable name and then backspace. You will see the displayed numeric value change. Then you hit return and the change will take effect.
Try this on a simple model first.

カテゴリ

Help Center および File ExchangeModel, Block, and Port Callbacks についてさらに検索

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by