sf_for (Simulink model) Open this Model

FOR Loops

With the use of flow charts, Stateflow allows you to create C-Code or M-Code statements such as the FOR loops. This particular demo shows how you can create a simple FOR Loop in Stateflow using an input from Simulink. The equivalent statement in MATLAB is as follows:


for i=1:20
   for_output = input(i)
end
for_output = 0;

where INPUT is a ramp input with a slope of 1 simulated for 10 seconds. Notice how the final_output is set to 0 after the FOR loops is exited. This is also apparent in the Scope from the Simulink model.