title: SIMULINK Holding Previous Value of a Signal
body: <p>I am trying to implement a pulse generator in SIMULINK that needs to know the previous 2 input values i.e. I need to know the previous 2 state values for the input signal. Also, I need to know the previous output value.</p>
  
  <p>My pseudo code is:</p>
  
  <pre><code>IF !input AND  input_prevValue AND !input_prevValue2
      output = !output_pv
  ELSE
      output = output_pv;
  </code></pre>
  
  <p>I know that I can use legacy function importer and use C code to do this job in SIMULINK. However, the problem arises when you apply a configuration reference set to your model. The key problem is the flexibility. When you use this model somewhere else (say share it with a colleague or whoever), unless you have used a configuration reference set, you can rebuild the code (i.e. from S-Function Block) and run your model. But you cannot rebuild the code if the configuration reference set is applied.</p>
  
  <p>My solution would be to implement the logic in a way that I can do the same without C functions. I tried to use the memory block in SIMULINK but apparently it doesn't do it. Does anyone know how to hold previous values for input and output in SIMULINK (for as long as the model is open)?</p>