시뮬레이션 중간에 s-function을 초기화(clear mex) 할 수 있나요?

7 ビュー (過去 30 日間)
종한 김
종한 김 2022 年 6 月 14 日
回答済み: Yash Sharma 2023 年 9 月 6 日
안녕하세요.
clear mex; 함수를 이용하면 c 코드로 이루어진 s-function의 모든 변수가 초기화되는 것으로 알고 있습니다.
시뮬레이션 중간에 시스템이 down되는 상황을 구현하고 싶습니다.
시뮬레이션 시작과 끝 사이에 s-funciton을 초기화할 수 있는 방법이 있을까요?
감사합니다.
  1 件のコメント
종한 김
종한 김 2022 年 6 月 14 日
참고로 enable block을 이용하여 disable이 되는 상태를 만들어보았는데, 이때는 disable 되기 전 변수들의 상태가 유지되고 다시 enable 시켰을때 초기화된 s-function이 아닌 그전 상태를 가지고 시작하는 것으로 확인됩니다.
위와 달리 s-function을 중간에 초기화하고 다시 시작하는 방법을 알고 싶습니다.

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

回答 (1 件)

Yash Sharma
Yash Sharma 2023 年 9 月 6 日
I understand that you want to simulate a system failure and want to re-initialize S-function in middle of simulation.
To initialize the S-function in the middle of the simulation, you can follow these steps:
  • Define a flag or condition within the S-function to indicate the reset state. For example, you can use a boolean variable like isReset and initialize it to false.
  • In your simulation loop or control logic, when you want to simulate a system failure and reset the S-function, set the reset flag to true. This can be done using an appropriate trigger or condition.
  • In the S-function's “mdlInitializeSizes” or ”mdlInitializeConditions” function, check the value of the reset flag. If it is true, reset the necessary variables or parameters to their initial values.
  • Ensure that the reset flag is reset to false after the initialization is complete. This can be done within the S-function's “mdlStart” or “mdlOutputs” function, depending on your specific requirements.
By following these steps, you can reset and initialize the S-function between the simulation start and end, simulate a system failure and restart the S-function in a clean state.
Please note that the implementation details may vary depending on your specific S-function code and simulation requirements.
Find below the link to the documentation for the relevant functions that you may find useful for implementing the desired functionality:

カテゴリ

Help Center および File ExchangeBlock and Blockset Authoring についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!