How to set/assign a value to Subsystem inports from .m file?

5 ビュー (過去 30 日間)
Ramesh Akula
Ramesh Akula 2020 年 10 月 8 日
回答済み: Sameer 2025 年 5 月 8 日
I would like to assign a value to Simulink Subsystem inports from .m file. Is it possible to do this in Simulink? Idea is to check Subsytem functionality independent from other subsytems. I know that its possible by using "Simulink Test" but I am would like to do with .m or any other custom file without using "Simulink Test".

回答 (1 件)

Sameer
Sameer 2025 年 5 月 8 日
Yes, you can assign values to Simulink Subsystem inports from an '.m' file, without needing Simulink Test.
The easiest way is to use "From Workspace" blocks in place of the Inport blocks inside your subsystem. Here’s how:
1. Replace the Inport block in your subsystem with a From Workspace block.
2. In your '.m' file, define the input signal as a variable (for example, using a timeseries object)
t = (0:0.01:10)';
u = sin(t);
input_signal = timeseries(u, t);
3. Set the From Workspace block's variable name to "input_signal".
Now, when you run your model, the subsystem will use the signal you defined in your '.m' file as its input. This lets you test your subsystem independently from the rest of the model.
Please refer to the following MathWorks documentation link:
Hope this helps!

カテゴリ

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

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by