필터 지우기
필터 지우기

Matlab Function in simulink

조회 수: 1 (최근 30일)
LODOVICO MANILDO
LODOVICO MANILDO 2021년 6월 22일
댓글: Walter Roberson 2021년 6월 22일
Hi everyone,
I would like to create a Matlab Function in a simulink model. The function would be used in order to create a mask in which I can choose one over 4 different cases. For each one of this cases I would like to have a dedicated simulation stop time.
My code is this one:
function y = fcn(value)
T_sim=0;
if (value==1)
T_sim = inf;
elseif (value==2)
T_sim = 10;
elseif (value==3)
T_sim = 15;
else
T_sim = 20;
end
y = value;
I'm trying with this code, but I think that T_sim variable is local, and then outside from that function it has no effect. How can I solve it?

답변 (1개)

Walter Roberson
Walter Roberson 2021년 6월 22일
If you look at the first diagram there, imagine using the output from your function block instead of a Constant block. You would compare to the Clock, and when the limit was reached, the STOP block would act.
  댓글 수: 2
LODOVICO MANILDO
LODOVICO MANILDO 2021년 6월 22일
Thanks for answering that fast, however its not usefull in this case, since the output of the function is the value itself.
I'm wondering to understand how can I update, let's say "automatically", the dedicated stop time variable, which in this case is called "T_sim".
I even tried to declare it as:
global T_sim;
But it doesn't work.
As you can see from the attached picture, the value is used to select one of the four possible speed references which have different durations.
Walter Roberson
Walter Roberson 2021년 6월 22일
Well, don't do that then: make T_sim a second output from the MATLAB Function Block.
If you are for some reason required to make T_sim a global variable in order to access it from other places, then you have to register it as a datastore https://www.mathworks.com/help/simulink/ug/model-global-data-using-data-stores.html
... but it seems to me much easier to just emit it from the function block as an additional output.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by