フィルターのクリア

How to change the input of a subsystem using open_system

2 ビュー (過去 30 日間)
eblee
eblee 2023 年 12 月 22 日
編集済み: Angelo Yeo 2023 年 12 月 26 日
There are two blocks in the model I designed: MATLAB Function and testSub.
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
Angelo Yeo 2023 年 12 月 22 日
Can you describe the desired workflow? What do you want to do in the end?
eblee
eblee 2023 年 12 月 25 日
I want to run or stop the testSub block with a MATLAB Function. So I implemented code to control testSub using open_system.
At this time, I wonder if there is a way to directly set the input to testSub with set_param.

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

採用された回答

Angelo Yeo
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.
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 件のコメント
eblee
eblee 2023 年 12 月 26 日
I used set_param and open_system because I wanted all inputs to always be input in a state where the model was initialized.
Regarding your answer, is there a way to initialize the model every time for all inputs?
Angelo Yeo
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 ExchangeProgrammatic Model Editing についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by