How to change the input of a subsystem using open_system
1 次查看(过去 30 天)
显示 更早的评论
There are two blocks in the model I designed: MATLAB Function and testSub.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1574637/image.png)
At this time, I would like to control the input of testSub using MATLAB Function.
So I designed the code as below.
function y = fcn(u)
coder.extrinsic("set_param");
coder.extrinsic("close_system");
coder.extrinsic("open_system");
set_param('untitled1/Subsystem/testSub','OpenFcn','');
open_system('untitled1/Subsystem/testSub','OpenFcn');
y=1;
I want to set input to 'u' in set_param, but is there any way?
help will be appreciated.
Thanx
2 个评论
采纳的回答
Angelo Yeo
2023-12-25
I understood that you want to input a signal to input port. You don't need to use set_param. You can use Data Import/Export functionality in Simulink. See the documentation below which has examples on how to implement them.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1576137/image.png)
Moreover, if you are to create test cases for Simulink models, you can consider using Simulink Test. You can author tests with shipped funcitonalities such as importing external file data for test cases, e.g., Excel spreadsheet. Please refer to the doc below for detailed information on how to create tests with user-defined input signals.
2 个评论
Angelo Yeo
2023-12-26
编辑:Angelo Yeo
2023-12-26
You can use variables from base workspace. This means you can always set your variables as you need and run simulation with the sim command in an m-file.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Programmatic Model Editing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!