Matlab Function in simulink
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Walter Roberson
am 22 Jun. 2021
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 Kommentare
Walter Roberson
am 22 Jun. 2021
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.
Siehe auch
Kategorien
Mehr zu Event Functions finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!