2
votes

I have a matlab function block (which is not relevant) whose input is his previous output (loop). For example, if in a sample period the output is X, his input in the next sample period will be X, and so on.

Simulink model simplificated

This image shows a simplification of my simulation. I initialize the input of my function for the first loop.

The problem is that matlab functions recieves an event based signal from de initialization block in the first sample period (zero-duration), which I must convert to a timed based signal (so I can apply the unit delay that avoids an inifite loop, and allows to generate the next input as explained before). So, when I do so, I lose the information contained in the event-based signal (due to the zero-duration values) and the loop does not work. If there was a way to intialize the loop in the time-based domain (green part of the image) so, in the first sample time, it is not a zero-duration signal, it would avoid the problem.

Is there any way to do so? Or, a different approach for this problem?

1

1 Answers

2
votes

Two approaches come to mind

  1. The initial condition can be set in the Unit Delay block, so it's not clear from your simplified example why you need the specific Initialization block.

  2. You could just use a persistent variable inside the MATLAB Function block to maintain the state from one execution of the block to the next (noting that since it is event driven the block may not get called at every time step, only at each event triggger).