Matlab Function in simulink
조회 수: 1 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
답변 (1개)
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
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 Center 및 File Exchange에서 Event Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!