Get current simulation step (or time) in Simulink
조회 수: 111 (최근 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!