title: Matlab and Simulink simulation using set_param and get_param
body: <p>I am using the command set_param and get_param to control a very simple simulink model, which only consists of a clock block and a scope. What I want is to let the simulink model run, get the real-tiem output of the clock block from Simulink to Matlab and stop the simulation when the clock value is greater than 5. The following is my Matlab script:</p>
  
  <pre><code>Simulink_Model='co_simulation_sl';                      
  load_system(Simulink_Model);
  
  open(Simulink_Model);
  time=0;
  
  while time&lt;5
  
  if strcmp (get_param(Simulink_Model,'SimulationStatus'), 'stopped')
        set_param(Simulink_Model,'SimulationCommand','start')
     elseif strcmp (get_param(Simulink_Model,'SimulationStatus'), 'paused')
        set_param(Simulink_Model,'SimulationCommand','continue')
     end
     set_param(Simulink_Model,'SimulationCommand','pause')
     block = 'co_simulation_sl/Clock';
     rto = get_param(block, 'RuntimeObject');
     time = rto.OutputPort(1).Data;
  end
  set_param(Simulink_Model,'SimulationCommand','stop')
  </code></pre>
  
  <p>enter image description is <a href="https://i.stack.imgur.com/sBmy0.png" rel="nofollow noreferrer">here</a>.</p>
  
  <p>However the while loop cannot run itself correctly. I can only observe the change of the variable "time" when I manually pause and continue the Simulink model. I'm using a fixed simulation time step of 0.1s.</p>
  
  <p>I have already searched a lot, but still cannot find any reason. Could you help me? Thank you in advance.</p>