Run Matlab FUNCTION at the end of Simulink simulation

조회 수: 56 (최근 30일)
Alberto Mora
Alberto Mora 2020년 5월 30일
댓글: Alberto Mora 2020년 6월 5일
Hello,
in a simulink simulation I compute some signals.
At the end of the simulation, when the system reach the steady-state condition, I want to use the final value of such signals to create a custom 3D plot. To do that I already built a Matlab FUNCTION block.
I don't want to run such Matlab FUNCTION block during the simulation because the computational time grows so much, and moreover I am interested only in the final value (steady-state).
How can I run such "Matlab FUNCTION block" only at the end of the simulation?
Thanks and best regards
  댓글 수: 2
madhan ravi
madhan ravi 2020년 5월 31일
Why not use To block and then use those results in a script file?
Alberto Mora
Alberto Mora 2020년 5월 31일
Hello Madhan,
my idea was to create a custom simulink block (with all the instructions for the plot) and add it to my library.
Therefore I want to have all the instructions inside the custom simulink block. I don't want to have a piece of code in a separate script file.
Do you have suggestion to do that?

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

채택된 답변

Sai Sri Pathuri
Sai Sri Pathuri 2020년 5월 30일
You may use StopFcn callback in your model. Refer the following link for Model callbacks. Expand Model Simulation Callback Parameters in the below documentation for StopFcn.
  댓글 수: 7
Sai Sri Pathuri
Sai Sri Pathuri 2020년 6월 2일
Okay, In order to avoid overwriting and plot only last time step data, you may try this.
In constant block you used for FlagEndSim, use constant value as
[zeros(lengthOfOutput-1);1]
and Sample time as below. This is to retain previous sample rate after conversion by buffer
stepSize*lengthOfOutput
After the constant block, use buffer with output buffer size of 1.
With these changes, you can plot the results of only last simulation.
This is an example I tried at my end. I used a StopTime of 10 and a variable solver. For this, the output is of length 51 and step size is 0.2 (obtained from tout)
So, I have used the following settings
% Constant value
[zeros(50);1]
% SampleTime
0.2*51
Alberto Mora
Alberto Mora 2020년 6월 5일
At the end I decided to follow partially your suggestion, comparing the time of the simulation (using clock) and a time defined by the user that set like few ms before the end of the simulation.
It is a pity that does not exist a in matlab way to call a matlab function exacly at the end of the simulation... But it's ok, I solve the problem so does not matter.
Thank for the help and best regards.
Alberto

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by