Why an initialization function in Simulink Dialog box code is not going to work?

조회 수: 9 (최근 30일)
Hello everyone,
Need help. I have a simulation in Simulink and in dialog box code(in mask editor) I have an initialization code which takes a few parameters from the dialog box and calculates TimeFinal which is parameter for Stop Time of the simulation. It doesn't want to calculate that parameter from dialog box code when I want to run a simulation(Error evaluating expression 'TimeFinal' for 'StopTime' specified in the Configuration Parameters dialog for block diagram), but when I put that initialization function in Model Settings->Model Properties->Callbacks->InitFcn then it works.
Would someone be so kind to explain to me this initialization hierachy in Simulink and if someone has a link for a comprehensive Dialog Box tutorial(which includes code in dialog box) I would really appriciate?
Thankful in advance

채택된 답변

Ritish Sehgal
Ritish Sehgal 2022년 6월 28일
It is my understanding that when you try to execute the initialization code in Mask Editor it gives an error while evaluating the expression.
You can enter any valid MATLAB expression, consisting of MATLAB functions and scripts, operators, and variables defined in the “mask workspace”. Initialization commands run in the “mask workspace”, not the base workspace. You can check if that is the case.
I am attaching a link to the documentation which gives the use cases and best practices for Mask Initialization:
There are some rules and conditions that apply for mask initialization commands. Below is a link which gives an overview of the Code Pane and mentions those rules as well:
Hope it helps!!
  댓글 수: 1
Lazar Dulovic
Lazar Dulovic 2022년 6월 28일
편집: Lazar Dulovic 2022년 6월 28일
Well, I have recently discovered that there are mask workspace, model workspace and base workspace. Only reasonable conclusion for me was that that variable doesn't go to base workspace, as you are suggesting to me.
But I am still looking for a solution to start it from a mask. I hope I will find the solution from the links you posted.
Thank you, very much!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by