フィルターのクリア

Change Simulink.Signal initial value programmatically

3 ビュー (過去 30 日間)
Aviad Aviad
Aviad Aviad 2018 年 6 月 9 日
回答済み: Brahmadev 2024 年 2 月 8 日
Hi,
I used the following guide to create a Simulink.Signal object in my Simulink model via Model Explorer: https://www.mathworks.com/help/simulink/ug/using-global-data-with-the-matlab-function-block.html
I gave the Simulink.Signal object an initial value via the model explorer and used it in a MATLAB function block in my model, but its value is constant and I would like to be able to change it in my main program.
My question is: how can I set the value of this Simulink.Signal programmatically using MATLAB code?
Thanks in advance.

回答 (1 件)

Brahmadev
Brahmadev 2024 年 2 月 8 日
For programatically editing a Simulink.Signal object from the command window, we should first define it in the base workspace. See example below:
>> y = Simulink.Signal
>> y.CoderInfo.StorageClass = "ExportedGlobal";
>> y.CoderInfo.Identifier = "y"
>> y.InitialValue = ""
Now, "y" can be used in simulink by using the following steps:
  1. Open th Simulink mode. Right click on the Signal that you want to connect to "y". Go to properties. This will open the "Signal Properties" dialog box.
  2. Enter y in the Signal Name edit field.
  3. Enable "Signal name must resolve to Simulink signal object"
Now you can programatically set the value of Simulink.Signal object. Hope this helps!

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by