title: How to implenet a timed loop in a Matlab function block
body: <p>I'm very new to Matlab Simulink and I'm trying to implement a loop in the Matlab Function Block that goes on non-stop during the whole simulation.
  Input:</p>
  
  <p>"t" from a simple clock to make it go on until the simulation lasts.</p>
  
  <p>"v" and "i" what gives a specific "p*" value, by changing the ouptut "D" a little bit I want to check if this "p*" value gets bigger or smaller (in the whole model "v" and "i" are influenced by "D")</p>
  
  <pre><code>function D = fcn(v,i,t)
  %#codegen
  p1 = v*i;
  D = 0.5;
  D = D + 0.05;
  
  while t &gt; 0
  
  p2 = v*i;
  
  if p1 &gt; p2 
    D = D - 0.05;
  
  else
    D = D + 0.05;
  
  end;
  
  p1 = p2;
  
  end;
  </code></pre>
  
  <p>The Function Block says it is correct, but as I start to run it, it freezes. The next step I wanted to do (but never got there) is to put a little timer in it, to execute this loop lets say every 0.01 sec or something. Is that compliable with a Matlab Function Block or is there any way achieving this?</p>