running m-file from Simulink

조회 수: 21 (최근 30일)
Khristopher
Khristopher 2011년 12월 1일
답변: manu kasturi 2019년 6월 6일
Hi,
I have a m-file with the initial conditions for a simulink model. Currently I manually run the file before I run the simulation.
My questions are as follow:
1. Is there a way to have simulink automatically run the m-file when I, either open the model, or start the simulation?
2. Would it be possible to run the m-file with the initial conditions during the simulation?
Further Information for question 2:
The m-file with the initial conditions contains various parameters that depend on how the user decides to run the simulation (manually or using autonomy) (it's basically a flight sim). I would like to be able to change flight modes within the simulation by simply re-running the m-file.
Thank you very much in advance for your time.

채택된 답변

Kaustubha Govind
Kaustubha Govind 2011년 12월 1일
  1. Yes, you can configure Model Callback Functions to call MATLAB code at specific times in the model lifetime. You can use PostLoadFcn to call something right after a model has been loaded, and InitFcn to call during model update, or right before simulation.
  2. You can run MATLAB-file during simulation (as if it were one of the blocks) using the Interpreted MATLAB Function, but initial conditions are needed at the beginning of simulation, so using the InitFcn callback is a better place to do that.
  댓글 수: 3
Khristopher
Khristopher 2011년 12월 1일
I have successfully applied your solution, Thank you very much!
Manikandan R
Manikandan R 2019년 3월 16일
편집: Manikandan R 2019년 3월 16일
if my m file contains printing satements it is not on the comaand window why???

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

manu kasturi
manu kasturi 2019년 6월 6일
I have a similar kind of problem.
In my case, I want user to select one m script from a list.
Could you please help me in this regard?

카테고리

Help CenterFile Exchange에서 Model, Block, and Port Callbacks에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by