Syncing iterations of the loop and the time step of the simulation
Show older comments
Dear all,
I am using a For loop in my simulink model. Let's say simple factorial function.
It receives a number(for instance 4) and returns the factorial of the input(24).
1) The main question is
The whole loops (i=1,...4) occurs in one single time stamp of the simulation. Also at the MATLAB document I found a note that
"Simulation time does not advance during iterative executions of a While/(For) Iterator Subsystem block. Nevertheless, blocks in the subsystem treat each iteration as a time step. .."
This is not what I want.
I want in a single step of my simulation i turns to 1, then in the next step it becomes 2, and ,....
How I can do that?
(The type of the solver selection is Fixed-Step but the simulation time is 10 seconds, but we do not want to change the simulation time starting and ending)
2) Does the functions that we wrote as MATLAb function that has a loop inside the code, treats similarly?
I mean the whole code is run once in one single step.
If yes, How I can change the code so each iteration performs in each single step of the simulation.
3) When I do not select "states when starting" to "reset", it returns zero as an output(I already set initial value of the delay to 1). I do not undrestand why?



Thanks...
Accepted Answer
More Answers (1)
chandini
on 20 Aug 2025
0 votes
how to do the iiterations for the entire system for a simulink model
Categories
Find more on General Applications in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!