Get current simulation step (or time) in Simulink
114 次查看(过去 30 天)
显示 更早的评论
Hello,
in my Simulink simulation, I need to access certain elements in an array, the indices depending on the current simulation step.
I found a solution that works, but takes some possibly avoidable simulation time. Because I need to conduct many simulations I would like to know if there are more efficient solutions.
Just to maybe better understand what I want to do, my current solution:
I calculate the current simulation step using the clock Simulink-block as in this image:
Then I use this as an input to some selector blocks to get the correct entries from an array.
I already checked, what needs much time is the part in the picture. Not the selector-blocks.
So my problem would be solved if there was an option to get the current simulation step (or alternatively, the current simulation time, for I use fixed step size) directly in Simulink, without using a clock. Maybe it is available somewhere as a variable/a parameter?
I am also open to completely different solutions.
I would be thankful for any help!
Best Regards
Sofie
0 个评论
回答(1 个)
Jim Riggs
2023-5-24
It looks like what you want is a simple counter. Try this:
You don't need to use a time generator and a multiply (and floor). The above will provide a simple integer count using only a single add operation. This will increment by one every pass through the simulation.
Note that on the first pass the "Memory" block will have a default value of zero, therefore "Count" will be equal to 1 from the start. You can change this by changing the initial value in the memory block if you want to start with a different value. For example, if you set the initial value of the memory block to -1, "Count" will start from zero (1 + (-1) ).
2 个评论
Karim Darwich
2024-5-14
@Jim Riggs Good morning sir
Is there an other way that we can access step time without using a memory bloc ?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Sources 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!