Based on the information provided you can proceed like this:
1) Enter the array as input to matlab function ( Representing Circular buffer)
2) For circular buffer you can try this matlab code in the function.
function y = fcn(u,IC, bufferLength)
buffer = IC;
buffer = IC*ones(1,bufferLength);
error('IC must either be scalar or the same dimensions as buffer length')
y = buffer;
buffer = [u buffer(1:end-1)];
3) With each buffer update, you can update counter variable and send that as an input to the next circular buffer, which in turn would keep storing values.
Hope it helps !