![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/172067/image.png)
How do I lower the numerical accuracy of Simevents/Simulink simulation time or the time written from a clock block?
4 次查看(过去 30 天)
显示 更早的评论
In a SimEvents model set to use variable discrete time steps:
I only want to use the time of the simulation to one decimal place. I write the simulation time to entities at certain times and use that time in an attribute function block.
If the time of an event is set to happened every six steps and I am checking if it is at 6, 12, or 18 etc. I use an equality in the function. Most times the time comes in as 6.000000000000000 but on occasion will be 5.999999999999998 and this causes the conditional check to fail.
Currently I just curTime = round(curTime); in the function but is there a way to lower the number of decimal places used to track the time in the model itself? Is there some other aspect of the this I should be aware of?
How might the absolute tolerance, relative tolerance, and time tolerance affect the time written to an entity from a clock block?
I am looking for ways to change this behavior in the model settings and not by using a rounding block or some other function in the attribute function if it is possible.
Thank you.
0 个评论
回答(1 个)
Ryan G
2012-9-25
You want to specify the datatype that suits your use case. If you are using a decimal you could potentially choose fixed point (excessive in this case) or utilize an integer. To do this you can utilize data conversion block. However, this will still have to round to convert to an integer.
Since you cannot set the datatype explicitly inside the clock, you can create your own using a couple blocks. You can see how I created a clock to run at 1hz below:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/172067/image.png)
Note that the sample time in the constant and unit delay blocks is 1.
4 个评论
Ryan G
2012-9-26
What that block is doing, assuming you haven't specifically set the sample time of the block, is inheriting the sample time of the 'event filter'. It's not technically triggering, where it activates based on a change in signal to the trigger.
The reason I used the implementation above is that it allows you to define time using an integer without rounding. What I believe is actually happening with your issue it probably the same as this, where the way the time in the clock block is defined does not match the way the simulink time is defined.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Discrete-Event Simulation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!