フィルターのクリア

How to set a variable in the simulink workspace from the model itself?

1 回表示 (過去 30 日間)
David Boelke
David Boelke 2023 年 5 月 29 日
編集済み: cr 2023 年 6 月 1 日
My simulink Model uses Variables from its Model workspace. I can change those variables in the "Model Explorer" and from a matlab script. The problem is, that the value of those variables are the result of a calculation, so using the model explorer is not an option and using an external matlab script is cumbersome. I want to change the value from a signal in the model, meaning I can set a constant, this goes through a calculation, to produce the values for the variables, the variables are set and the model can begin. Is that possible? Is there an alternative?
  2 件のコメント
Paul
Paul 2023 年 5 月 29 日
Hi David,
Is the variable that results from the calculation that starts from the constant going to be used as a parameter in a block in the model?
David Boelke
David Boelke 2023 年 5 月 30 日
Hi Paul, Yes. I want to set the constant, Pass it through the calculation, which results in my parameters and then use those parameters in a transfer function.

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

回答 (1 件)

cr
cr 2023 年 5 月 30 日
編集済み: cr 2023 年 6 月 1 日
You can use model callback functions. E.g. Preload, postload, init. See more info here https://mathworks.com/help/simulink/ug/model-callbacks.html
To set up a cb just rightclick in the white space and select Model properties > Callbacks tab. You can select the preload or init callback and write your matlab code there. Or write the code in a separate m file and then call the script name in the callback function.
Regards

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by