How to know a input is expected when compiling Simulink model?

7 ビュー (過去 30 日間)
Sohil Shrestha
Sohil Shrestha 2023 年 5 月 15 日
コメント済み: Sohil Shrestha 2023 年 5 月 16 日
I have a workflow which involves compiling a lot of Simulink models from different sources.
To fully automate the process, I am compiling using a matlab script. However, some of these Simulink models ask for user input when compiling which ultimately require user intervention for the script to proceed. Is there a way for detect that an input is expect and auto handle it (say with a return key) through the matlab script?
Also, Is there any subroutine that kills a running function based upon a pre specified time or timeout?

回答 (1 件)

Shaik
Shaik 2023 年 5 月 16 日
Hi,
Yes, you can automate the compilation process of Simulink models and handle user inputs using MATLAB scripting. Here are some suggestions:
  1. Simulink Model Compilation: To compile Simulink models using MATLAB script, you can use the sim function or the rtwbuild function. These functions allow you to programmatically compile Simulink models without requiring user intervention. For example, you can use the following command to compile a Simulink model:
rtwbuild('model_name');
  • Handling User Inputs: If a Simulink model requires user input during compilation, you can use the set_param function to set the desired values programmatically. This way, you can provide the necessary inputs without manual intervention. For example, if a block parameter requires a specific value, you can set it using the following command:
set_param('model_name/block_path', 'parameter_name', 'value');
  • Handling Timeouts: MATLAB provides the tic and toc functions for measuring elapsed time. You can utilize these functions to set a timeout for a running function. By periodically checking the elapsed time, you can terminate the function if it exceeds the specified timeout. Here's an example:
timeout = 60; % Timeout in seconds
tic;
while toc < timeout
% Run your function here
end
Additionally, you can also use the timer object in MATLAB to execute a specific function after a specified timeout. This can be useful if you want to perform certain actions when a timeout occurs.
  3 件のコメント
Shaik
Shaik 2023 年 5 月 16 日
If you don't have prior knowledge of which specific block in the Simulink model is responsible for issuing input requests, it can be more challenging to detect the source dynamically. In such cases, you may need to explore alternative approaches to identify the source of the input request. Here are a few suggestions:
  1. Monitor block execution: You can monitor the execution of each block in the Simulink model to identify which block is actively executing during the time when the input request occurs. This can be done by adding logging or diagnostic code to each block in the model to track their execution.
  2. Analyze block connectivity: Analyze the block connectivity in the Simulink model to identify potential sources of input requests. Look for blocks that are connected to external signals or user interfaces, as they are more likely to be responsible for requesting input.
  3. Simulate the model step by step: Simulate the Simulink model step by step and monitor the behavior to identify when an input request occurs. You can pause the simulation at different intervals and inspect the model state to determine which block might be responsible for the request.
Regarding the timeout function you mentioned, it appears that the code snippet you provided doesn't have any mechanism to detect input requests. The purpose of the timeout function is to limit the execution time of a section of code. In your example, the code is running a long loop, but it doesn't provide any indication of input requests or how to detect them.
To implement a timeout mechanism for detecting input requests, you would need to have a method in place that actively checks for input events or conditions. The timeout function could then be used to limit the time spent checking for input within a specified time period. However, the specific implementation details would depend on the nature of the input requests and the interfaces you are working with.
Please provide more information about the context and nature of the input requests you are trying to detect, and I can provide more tailored suggestions.
Sohil Shrestha
Sohil Shrestha 2023 年 5 月 16 日
Thank you for the suggestion.
Detecting input and timeout feature was two non-overlapping suggestion I was asking for.
The condition I need timeout feature is: Say I am compiling a Simulink models and it is taking way too long (e.g. more than 15 mins), in that case I want to abandon compiling (say Ctrc +C) and move on to next script in the pipeline.

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

カテゴリ

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