How to change evaluation time of a Matlab Function in Simulink
조회 수: 18(최근 30일)
I had a simscape model whose simulation was relatively short. I added a block of a Matlab Function to the model to compare by an algorythm some of the signals to control the state of a switch. Although the algorythm is quite simple, the simulation time now is ridicously long. Do you now how can I reduce it? Is there any option to change the step time at which the function (ONLY THE FUNCTION) is evaluated?
Thanks in advance!
Yoshi Minagawa 2021년 7월 14일
Although I didn't see your model and so I couldn't find the reason of the problem, I described the tips for this problem bellow. I hope this will help for you.
1. Set sample time of MATLAB function
In block parameters dialog(right click the block and select "Block Parameter") , you can set sample time for this block. It may be necessary to place Rate transition blocks before and after the range where the sample time was changed. (Please see the URL below for details)
2. Using local solver for simscape
Using Solver Configuration block you can use local solver for simscape. It enable you to use different solver to simulate simulink model and simscape model individually.
3. Profiling the reason of stack
To profile the reason of stack, you can use "Solver Profiler". Please see the picture how to start this app. (Please see the URL below for details)
Please be careful that there is not Algebra loop in your model. If there is, that can make slower the simulation speed. In another case, using stiff solva might improve this problem (ode23t or something) because the model may be stiff due to the mixture of simulink model and simscape model.
I hope this will help.
Jonas 2021년 8월 30일
If you put a MATLAB function block in your model, it will evaluate the MATLAB function code at each sample time. (depends on your model's architecture, but I am assuming so) This can indeed lengthen your simulation.
If you do not need the execution of the MATLAB function block each sample time, you can put the MATLAB function block inside a Triggered Subsystem, and then you can add a Step block with a certain step time to trigger the execution and calculation of the MATLAB function block just once. You could trigger the Triggered Subsystem block again to make the MATLAB function block calculate again, but then you need something more advanced than a step block, maybe a Pulse Generator if you like.
Hope it helps or gives inspiration.