Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

control simulink from M-file

I am trying to control a simulink from a M-file. What I want to do in the M-file is give the simulink model some input, run the simulink model, change one input value at 0.6 seconds, continue running the simulink model with the new input.

I already know that by using set_param, I can start, pause and continue the simulink, but the problem is I don't know how to pause the simulink model at a certain time(0.6s), is it possible to get the current time from simulink model and read it in the M-file?

Another way I already know is using sim to run simulink model from 0 to 0.6s, and use SimState to save the information at 0.6s, then load these information to resume the simulation. I am trying to change the input before the simulation resumed, but it seems that the model will load the input values from the information it saved, it won't take the new input value.

I stuck in this problem for a very long time, could someone help me with this please?

Thank you very much.

like image 255
Academic losser Avatar asked Dec 12 '25 09:12

Academic losser


1 Answers

You can get the current time of a running simulation with:

get_param('simulink_model_name', 'SimulationTime');

So for instance by checking this value from your M-file during simulation by using

timer(...)

you can detect when the simulation is at 0.6 seconds.

like image 126
mmumboss Avatar answered Dec 14 '25 05:12

mmumboss



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!