control simulink from M-file

后端 未结 3 2042
清酒与你
清酒与你 2021-01-07 06:22

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

3条回答
  •  长发绾君心
    2021-01-07 06:41

    I used a combination of simulink and m-script to achieve a similar goal.

    In your model, add one 'assert' block. Double click it, and uncheck 'Stop Simulation when assertion fails'. In the 'Simulation Callback when assertion fails' field, add three commands:

    1. set_param(bdroot,'SimulationCommand','pause');
    2. run('myscript.m'); %insert the script name
    3. set_param(bdroot,'SimulationCommand','continue');

    Now connect the inport of this block to a 'not equal to' relational operator. Connect the first inport of the relational operator to a clock (pls set the decimation for analog clock or the sample time [usually -1 for inherited] for the digital clock). The second inport is connected to constant block with a value of 0.6

    On simulating the model, the simulation will pause at 0.6 sec, execute the m-file to change the input parameter (considering that it's tunable) and then continue with the simulation.

    The assertion block is called when its input signal becomes 0. At 0.6 sec, the output of the relational operator will be 0.

    Let me know if it worked.

提交回复
热议问题