How to export simulink data to workspace during simulation?

后端 未结 3 1333
再見小時候
再見小時候 2021-01-05 03:47

I want to retrieve the data from simulink during simulation, and use serial network function to send these data to another program. Because I need to use an

3条回答
  •  长发绾君心
    2021-01-05 04:07

    Use get_param to read data from just at the current time. Also to send the data back to Simulink with set_param of a gain or another block.

    An example of get_param

    First load and start the simulation:

    load_system('myModel')
    set_param('myModel','SimulationCommand','Start');
    

    To read data on any line of your simulink model:

    1. Get a simulink block object (let's try a Clock with the name Clock):

      block = 'myModel/Clock';
      rto = get_param(block, 'RuntimeObject');
      
    2. Then get the data on its first (or any) output port (or input) of that block.

      time = rto.OutputPort(1).Data;
      

    You could do the reading, in a timer callback.

    Also this might be helpful: Command Line Functionality for Simulink

提交回复
热议问题