I have a large Simulnk model which takes quite long to run (+/- 30min).
Now I would like to set parameters and start the simulation using a m-file. If I do so, Simulink no longer shows me the progress of the simulation on the bottom.
I searched for solutions and I programmed a custom progress bar using the Matlab function waitbar() and an "Embedded Matlab Function" block inside simulink.
The code looks like this:
function fcn(u1, u2)
h = evalin('base','h');
perc = u1/u2 * 100;
waitbar(u1/u2, h, sprintf('Completed: %.05fs of %.05fs (%.05f%%)', u1, u2, perc)
Inside my Matlab skript I execute the simulation as follows:
h = waitbar(0,'Please wait...');
out = sim(...
This solution works but seems to slow down my simulation a lot, probably because this embedded function block is called within every simulation step. Also print functions like sprintf() are known to be not so fast.
Now there are several questions that come with this solution.
- I have not managed to "pass" my waitbar handler into this function block. That's why I am using the evalin() function in order to get it from the workspace. Is there a better way to do this?
- Is it possible to tell Simulink that it should only execute this embedded function block once in a while, for example, every 0.1s?
- I know that I can implement this functionality inside my Matlab skribt by using the get_param() function in order to get the current simulation time. However, I have not figured out how to run the sim() command in the "background" so that my Matlab skript continues and then can enter a loop in which the progress bar is updated. How can I implement that?
- Is there a general, better solution for this that offers more performance?
Thanks for any answers!