Get current simulation step (or time) in Simulink
108 ビュー (過去 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!