Number of values stored are more than the ratio of stop Time/Step size ?
1 次查看(过去 30 天)
显示 更早的评论
I am using presistance variables as cells to store values in the Matlab Interpreted block of simulink, My Step Size is 0.001 and my Stop Time 0.005 and the number of values stored is 16. (Even though I reduce the Stop Time to 0.001 the number of values stored is 4.) It seems Simulation file is called Matlab Interpreted block 16 times istead of 5 times. How can I fix this issue ?
5 个评论
Atsushi Ueno
2023-9-24
Thank you. Now I can confirm that the size of persistent variables increased by 1 per one execution of the function.
回答(1 个)
Walter Roberson
2023-9-24
See https://www.mathworks.com/help/simulink/ug/choose-a-solver.html and https://www.mathworks.com/help/simulink/ug/managing-sample-times-in-systems.html for more information about solver configuration.
Variable-step solvers are sort of like walking in a mountain in the dark, when equipped with a narrow-beam flashlight that you can use to send out quick pulses of light. Any one pulse of light might show that a particular spot in the distance has a particular height, but it doesn't directly tell you anything about what is in-between where you are and that spot, and any one pulse of light does not give you any direct information about what the best direction to travel is. The variable solver is instead like saying, "Taking a guess that you are currently safe to take a step that is so-many metres long, shine your light at several different places according to this carefully different pattern, and use the information from those locations to make a prediction about what the local terrain is like. To confirm that your prediction is right, shine your light at a different carefully-calculated location and make sure that the ground is within a certain range of heights: if it is, then trust your prediction of the local terrain and make the step. If the confirmation check shows a height that is not within a certain range, then that means that you misjudged the terrain, and start again from where you are but with a smaller step size -- but if your prediction was successful then increase your step size by a little."
Which is to say, that variable-step solvers evaluate the function at a number of places they do not intend to step to, in order to evaluate information about the local function space in order to be able to make good predictions of the best way to go. You typically have no reason to want to record the results at those locations that were probed: you typically only want to record the results at the locations that you actually step to. But with your persistent variable, you are recording information about every invocation, not just every successful step.
When you switch to discrete time, the solver switches to fixed-step rather than variable-step. You might also need to change some of the blocks in your model -- for example if you have integrator blocks you might need to switch to discrete integrator blocks.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!